我将元素划分为3个div:两个矩形和一个三角形。左矩形-带有图标的按钮,右矩形-图像和文本,三角形只是一个空的div。这就是您可以赋予div的样式,使其看起来像所需的三角形。
triangle: {
width: 0,
height: 0,
backgroundColor: "transparent",
borderStyle: "solid",
borderLeftWidth: 50,
borderRightWidth: 50,
borderBottomWidth: 100,
borderLeftColor: "transparent",
borderRightColor: "transparent",
borderBottomColor: "red",
transform: "rotate(90deg)" }
您可以这样进行,创建按钮组件,并使用css对其进行格式化,并使用伪元素创建箭头的尖端。
const App = () => {
const icon1 = "https://img.icons8.com/ios-filled/50/000000/crane.png"
const icon2 = "https://img.icons8.com/ios-glyphs/30/000000/interstate-plow-truck.png"
const ArrowButton = ( props ) => (
<div className="arrow_box" onClick={props.click} >
<div className="arrow_button"></div>
<div className="arrow_content">
<div className="arrow_content_img-box">
<img className="arrow_content_img" alt="icon" src={props.icon} />
</div>
<span className="arrow_content_text">{props.iconRef}</span>
</div>
</div>
)
const handleClick = () => {
alert('click')
}
return (
<div className="container">
<h1 className="title__primary">Arrow Button</h1>
<ArrowButton icon={icon1} iconRef={"pl001"} click={handleClick} />
<ArrowButton icon={icon2} iconRef={"fr005"} click={handleClick} />
</div>
);
};
ReactDOM.render(
<App />, document.getElementById("react")
);
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: sans-serif;
text-align: center;
}
.arrow_box {
width: 200px;
height: 60px;
margin: 5px;
cursor: pointer;
border-top: 2px solid #c9cdd0;
border-bottom: 2px solid #c9cdd0;
border-left: 2px solid #c9cdd0;
border-radius: 8px 0 0 8px;
background-color: #ffffff;
position: relative;
display: flex;
align-items: center;
flex-direction: row;
}
.arrow_box::before {
content: "";
position: absolute;
width: 40px;
height: 40px;
top: 50%;
left: 89.5%;
background-color: #ffffff;
border-top: 2px solid #c9cdd0;
border-right: 2px solid #c9cdd0;
transform: rotate(45deg);
margin-top: -21px;
}
.arrow_box:hover, .arrow_box:hover::before{
background-color: #006eff;
}
.arrow_button {
position: relative;
width: 56px;
height: 56px;
font-size: 1.5rem;
color: #ffffff;
background-color: #00122c;
border-radius: 6px 0 0 6px;
display: flex;
align-items: center;
justify-content: center;
}
.arrow_button::before {
content: "\2716";
}
.arrow_content {
position: relative;
display: flex;
align-items: center;
justify-content: space-evenly;
height: 56px;
width: 144px;
}
.arrow_content_img-box {
height: 50px;
width: 50px;
border-radius: 50%;
background-color: #ffe8aa;
display: flex;
align-items: center;
justify-content: center;
}
.arrow_content_img {
height: 35px;
width: auto;
filter: invert(75%) sepia(32%) saturate(7078%) brightness(100%)
hue-rotate(15deg) contrast(100%);
}
.arrow_content_text {
text-transform: uppercase;
font-size: 1.5rem;
font-weight: bold;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<div id="react"></div>