我要复制此内容:http://prntscr.com/k5wp2t 我尝试使用此代码,但是需要更好的设置。
<div class="button">MAGGIORI INFORMAZIONI</div>
.button {
position: relative;
display: block;
width: 120px;
height: 50px;
background: blue;
}
.button:after{
position: absolute;
bottom: 0;
height: 0;
width: 0;
left: 30%;
border: 30px solid transparent;
border-bottom-color: red;
content: "";
}
谢谢
答案 0 :(得分:1)
要使其成为一个真实的三角形,还需要在颜色的右侧加上border-right-color: red;
。之后,请记住确保三角形与按钮的大小相同(按钮的高度为50px;因此边框应为25px-而不是30),并将其放置在右侧,而不是从左侧30%
.button {
position: relative;
display: block;
width: 120px;
height: 50px;
background: blue;
}
.button:after{
position: absolute;
bottom: 0;
height: 0;
width: 0;
right:0;
border: 25px solid transparent;
border-bottom-color: red;
border-right-color: red;
content: "";
}
答案 1 :(得分:1)
请使用此
.button {
position: relative;
display: block;
width: 120px;
height: 50px;
background: blue;
padding-right: 40px;
overflow: hidden;
color:#fff;
padding-left:30px;
line-height:22px;
}
.button:after{
position: absolute;
bottom: 0;
height: 50px;
width: 30px;
right: -14px;
background: red;
content: "";
z-index: 1000;
transform: skew(-30deg);
}
<div class="button">MAGGIORI INFORMAZIONI</div>
答案 2 :(得分:1)
请使用此CSS代码
.button {
position: relative;
display: block;
width: 120px;
height: 50px;
background: blue;
padding-right: 40px;
overflow: hidden;
color:#fff;
padding-left:30px;
line-height:22px;
}
.button:after{
position: absolute;
bottom: 0;
height: 50px;
width: 30px;
right: -14px;
background: red;
content: "";
z-index: 1000;
transform: skew(-30deg);
}
答案 3 :(得分:0)
您需要将border-left设置为transparent以具有这样的形状并将其向右移动0px。
您还可以在(CSS的形状)[https://css-tricks.com/examples/ShapesOfCSS/]
上参阅这篇有关CSS的很好的文章。
.button {
position: relative;
display: block;
width: 270px;
padding: 20px;
background: #F47E3E;
display: flex;
align-items: center;
justify-content: center;
color: #FFF;
}
.button:after {
position: absolute;
bottom: 0;
right: 0px;
border-bottom: 62px solid red;
border-left: 62px solid transparent;
border-bottom-color: #000;
content: "";
}
<div class="button">MAGGIORI INFORMAZIONI</div>
答案 4 :(得分:0)
您还可以使用渐变背景:
background: linear-gradient(135deg, #F47E3E 220px,#000 0);
.button {
position: relative;
display: block;
width: 270px;
padding: 20px;
background: linear-gradient(135deg, #F47E3E 220px,#000 0);
display: flex;
align-items: center;
justify-content: center;
color: #FFF;
}
<div class="button">RICHIEDI INFORMAZIONI</div>