答案 0 :(得分:2)
试试这个
div {
min-height: 100px;
background: #D25A1E;
position: relative;
width: calc(50% - 30px);
}
.div1 {
float: left;
background-color:#5DC351;
width:130px;
}
.div2 {
float: right;
background-color:#FFF;
}
.div1:after, .div2:before {
content:'';
position: absolute;
top: 0;
width: 0;
height: 0;
}
.div1:after {
left: 100%;
border-top: 100px solid #5DC351;
border-right: 50px solid transparent;
}
.div2:before {
right: 100%;
border-bottom: 100px solid #FFF;
border-left: 50px solid transparent;
}
.inrtxt
{
font-size:50px;
margin:20px;
position:absolute;
}
#parent
{
background-color:#CcC;
width:300px;
padding:15px;
}
<div id="parent">
<div class="div1"><span class="inrtxt" style="color:white">Free</span></div>
<div class="div2"><span class="inrtxt" style="color:#5DC351">Wifi</span></div>
</div>
答案 1 :(得分:1)
使用以下内容:
<a class="btn-sloped" href="#">
<span class="sloped-border">free</span>
<span>wifi</span>
</a>
使用这些CSS:
.btn-sloped
{
border-radius: 10px;
color: green;
background-color: white;
display: inline-block;
font-size: 22px;
width: 260px;
line-height: 1;
height: 60px;
text-align: center;
}
.btn-sloped > span
{
display: inline-block;
position: relative;
padding: 15px;
float: left;
width: 160px;
}
.btn-sloped .sloped-border
{
background-color: green;
color: #fff;
border-radius: 10px 0 0 10px;
width: 100px;
}
.btn-sloped .sloped-border:before
{
content: "";
position: absolute;
right: -30px;
top: 0;
bottom: 0;
width: 0px;
height: 0px;
border-bottom: 52px solid transparent;
border-left: 30px solid green;
}
答案 2 :(得分:1)
另一个选择是使用transform: skewX(20deg);
css属性,但您需要考虑浏览器支持。
例如:
.bttn:after, .bttn:before {
position: absolute;
top: 0;
left: 0;
z-index: -1;
height: 100%;
content: '';
transform: skewX(20deg);
}
答案 3 :(得分:1)
有很多方法可以达到预期的效果。
以下是一种部署单个::after
伪元素的方法,该元素应用了skew()
转换。
此方法的一个优点是您可以将任何文本内容添加到第一个<span>
,并且背景效果将始终适应该文本内容的长度。
body {
background-color: rgb(224, 224, 224);
}
div {
display: inline-block;
background-color: rgb(255, 255, 255);
overflow-x: hidden;
border-radius: 9px;
}
div span {
display: inline-block;
position: relative;
height: 72px;
padding: 12px;
line-height: 72px;
font-size: 64px;
}
div span:nth-of-type(1) {
color: rgb(255, 255, 255);
background-color: rgb(95, 197, 78);
text-transform: uppercase;
border-radius: 9px 0 0 9px;
}
div span:nth-of-type(1)::after {
content: '';
position: absolute;
top: 0;
right: -10px;
width: 20px;
height: 100%;
background-color: rgb(95, 197, 78);
transform: skew(-10deg);
}
div span:nth-of-type(2) {
color: rgb(95, 197, 78);
padding-left: 16px;
border-radius: 0 9px 9px 0;
}
<div>
<span>Free</span>
<span>Wifi</span>
</div>