我想要创建如图片所示的三角形。有人知道如何实现这个效果吗?
.hero {
background: url(http://d.pr/i/eqn9+);
height: 200px;
position: relative;
}
.hero:before, .hero:after {
box-sizing: border-box;
content: " ";
position: absolute;
top:0;
display: block;
width: 50%;
height: 100%;
border: 30px solid orange;
border-bottom-color: pink;
}
.hero:before {
left: 0;
border-right: 20px solid transparent;
border-left: 0;
}
.hero:after {
right: 0;
border-left: 20px solid transparent;
border-right: 0;
}
使用更新的浏览器,可以使用clip-path
CSS属性。这要好得多,但你需要为IE / Edge和旧版本的浏览器提供备用方案。
<div class="triangle"></div>
<style>
.triangle {
width: 400px;
height: 400px;
background-color: blue;
clip-path: polygon(50% 0, 0 100%, 100% 100%);
}
</style>
使用CSS的三角形裁剪蒙版,可以裁剪图像以显示背景。
您可以使用CSS和SVG的clip属性来实现这种遮罩效果。
HTML
<svg width="0" height="0">
<clipPath id="clipping1" clipPathUnits="objectBoundingBox">
<polygon points="0 0, 0 1, 100 0, .6 0, .5 .2, .4 0">
</clipPath>
</svg>
<img class="clip-animation" alt="" src="http://c1.staticflickr.com/9/8449/7966887330_ddc8018682_h.jpg">
CSS
.clip-animation {clip-path: url(#clipping1);-webkit-clip-path: url(#clipping1); margin:100px; width:500px;}
body{ background-color:#CCCCCC;}
我有一个带有图片标签的口罩,您也可以将其与div元素或任何其他标签一起使用。
在此处检查工作演示。 http://jsfiddle.net/VijayDhanvai/495rpzdb/