我需要的是用两个右箭头实现按钮。用于切割按钮左侧的一个箭头和用于延伸按钮右侧的一个箭头(请参见附图)。
我现在成功的只是添加右箭头(见下图)。
以下是我当前的CSS。
.arrow-button {
width: 178px;
height: 82px;
position: relative;
object-fit: contain;
margin-right: 20px;
background-color: #be1a20;
}
.arrow-button:before {
content:"";
position: absolute;
left: 100%;
top: 26px;
width: 0;
height: 0;
border-top: 13px solid transparent;
border-left: 13px solid #be1a20;
border-bottom: 13px solid transparent;
}
.arrow-label {
font-family: Montserrat;
font-size: 13px;
font-weight: 500;
font-style: normal;
font-stretch: normal;
line-height: normal;
letter-spacing: normal;
text-align: center;
color: #ffffff;
margin: auto;
}
.layer {
font-family: Montserrat;
font-size: 24px;
font-weight: bold;
font-style: normal;
font-stretch: normal;
line-height: normal;
letter-spacing: normal;
text-align: center;
color: #ffffff;
margin: auto;
}
<div class="arrow-button">
<div class="row">
<label class="arrow-label">
SENT
</label>
</div>
<div class="row">
<label class="layer">
10
</label>
</div>
</div>
答案 0 :(得分:5)
与右箭头相似,使用:before和:after:
.arrow-button {
width: 178px;
height: 82px;
position: relative;
object-fit: contain;
margin-right: 20px;
background-color: #be1a20;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
.arrow-button:before,
.arrow-button:after {
content: "";
position: absolute;
left: 0;
top: 26px;
width: 0;
height: 0;
border-top: 13px solid transparent;
border-left: 13px solid white;
border-bottom: 13px solid transparent;
}
.arrow-button:after {
left: 100%;
border-left: 13px solid #be1a20;
}
.arrow-label {
font-family: Montserrat;
font-size: 13px;
font-weight: 500;
font-style: normal;
font-stretch: normal;
line-height: normal;
letter-spacing: normal;
text-align: center;
color: #ffffff;
margin: auto;
}
.layer {
font-family: Montserrat;
font-size: 24px;
font-weight: bold;
font-style: normal;
font-stretch: normal;
line-height: normal;
letter-spacing: normal;
text-align: center;
color: #ffffff;
margin: auto;
}
<div class="arrow-button">
<div class="row">
<label class="arrow-label">SENT</label>
</div>
<div class="row">
<label class="layer">10</label>
</div>
</div>
左侧唯一不同的右箭头是您需要重新定义的left
和border-left
个样式:
.arrow-button:after {
left: 100%;
border-left: 13px solid #be1a20;
}
注意,我使用flexbox进行垂直对齐文本,但您不必这样做,这与箭头无关。
答案 1 :(得分:2)
您可以使用渐变来执行此操作,而无需额外的标记或伪元素。你也可以有透明度:
.button {
width:200px;
height:100px;
display:inline-flex;
justify-content:center;
align-items:center;
padding:0 30px;
color:#fff;
background:
linear-gradient(to bottom left, transparent 50%,red 50.5%) right calc(50% - 10px) /30px 20px no-repeat,
linear-gradient(to top left, transparent 50%,red 50.5%) right calc(50% + 10px) /30px 20px no-repeat,
linear-gradient(to bottom right, transparent 50%,red 50.5%) left calc(50% + 10px) /30px 20px no-repeat,
linear-gradient(to top right, transparent 50%,red 50.5%) left calc(50% - 10px) /30px 20px no-repeat,
linear-gradient(red,red) bottom left/30px calc(50% - 20px) no-repeat,
linear-gradient(red,red) top left/30px calc(50% - 20px) no-repeat,
linear-gradient(red,red) center/calc(100% - 60px) 100% no-repeat;
}
body {
background:linear-gradient(to right,pink,yellow);
}
<div class="button">
some content
</div>
您还可以使用CSS变量使其动态化:
.button {
width:200px;
height:100px;
display:inline-flex;
color:#fff;
justify-content:center;
align-items:center;
margin:5px;
--w:30px;
--h:20px;
padding:0 var(--w);
background:
linear-gradient(to bottom left, transparent 50%,red 50.5%) right calc(50% - var(--h)/2) /var(--w) var(--h),
linear-gradient(to top left, transparent 50%,red 50.5%) right calc(50% + var(--h)/2) /var(--w) var(--h),
linear-gradient(to bottom right, transparent 50%,red 50.5%) left calc(50% + var(--h)/2) /var(--w) var(--h),
linear-gradient(to top right, transparent 50%,red 50.5%) left calc(50% - var(--h)/2) /var(--w) var(--h),
linear-gradient(red,red) bottom left/var(--w) calc(50% - var(--h)),
linear-gradient(red,red) top left/var(--w) calc(50% - var(--h)),
linear-gradient(red,red) center/calc(100% - 2*var(--w)) 100%;
background-repeat:no-repeat;
}
body {
background:linear-gradient(to right,pink,yellow);
}
<div class="button">
Some content
</div>
<div class="button" style="width:80px;--w:20px;--h:20px;">
Some content
</div>
<div class="button" style="width:120px;--w:40px;--h:20px;">
Some content
</div>
<div class="button" style="height:50px;--w:10px;--h:10px;">
Some content
</div>
答案 2 :(得分:1)
你走了:
.arrow-button {
width: 178px;
height: 82px;
position: relative;
object-fit: contain;
margin-right: 20px;
background-color: #be1a20;
}
.arrow-button:before {
content:"";
position: absolute;
left: 0;
top: 26px;
width: 0;
height: 0;
border-top: 13px solid transparent;
border-left: 13px solid white;
border-bottom: 13px solid transparent;
}
.arrow-button:after {
content:"";
position: absolute;
left: 100%;
top: 26px;
width: 0;
height: 0;
border-top: 13px solid transparent;
border-left: 13px solid #be1a20;
border-bottom: 13px solid transparent;
}
.container {
display: flex;
justify-content:center;
flex-direction:column;
vertical-align: middle;
height: inherit;
}
.arrow-label {
font-family: Montserrat;
font-size: 13px;
font-weight: 500;
font-style: normal;
font-stretch: normal;
line-height: normal;
letter-spacing: normal;
text-align: center;
color: #ffffff;
}
.layer {
font-family: Montserrat;
font-size: 24px;
font-weight: bold;
font-style: normal;
font-stretch: normal;
line-height: normal;
letter-spacing: normal;
text-align: center;
color: #ffffff;
}
<div class="arrow-button">
<div class="container">
<label class="arrow-label">
SENT
</label>
<label class="layer">
10
</label>
</div>
</div>