transform
(skew
和rotate
)来实现这种效果,而不需要使用兼容性较低的clip-path
。
.container {
width: 500px;
height: 300px;
background: linear-gradient(lightblue, dodgerblue);
position: relative;
overflow:hidden;
}
.container:after{
position:absolute;
content:"";
width:100%;
height:100%;
left:-50%;
top:-50%;
background:#D0021B;
transform-origin: 0 100%;
transform:skewY(15deg);
}
.container:before{
position:absolute;
content:"";
width:100%;
height:100%;
left:50%;
top:-50%;
background:#D0021B;
transform-origin: 100% 0;
transform:skewY(-15deg);
}
<div class="container"></div>
top:50%
。
.container {
width: 500px;
height: 300px;
background: url("http://i.imgur.com/5NK0H1e.jpg");
position: relative;
overflow: hidden;
}
.container:after {
position: absolute;
content: "";
width: 100%;
height: 100%;
left: -50%;
top: 50%;
background: linear-gradient(lightblue,dodgerblue);
transform: skew(10deg) rotate(10deg);
}
.container:before {
position: absolute;
content: "";
width: 100%;
height: 100%;
left: 50%;
top: 50%;
background:linear-gradient(lightblue,dodgerblue);
transform: skew(-10deg) rotate(-10deg);
}
<div class="container"></div>
polygon()
值轻松地创建此形状。
.wrap {
width: 30%;
height: 300px;
background: #4A90E2;
}
.wrap div {
height: 200px;
-webkit-clip-path: polygon(0% 0%, 100% 0%, 100% 90%, 50% 100%, 0% 90%);
clip-path: polygon(0% 0%, 100% 0%, 100% 90%, 50% 100%, 0% 90%);
background: url('http://i.imgur.com/5NK0H1e.jpg');
background-size:cover;
}
<div class="wrap"><div></div></div>