可以通过将border-radius 应用于覆盖元素来完成。
Demo
.angled-triangle {
background-color:orange;
width:200px;
height:50px;
position:relative;
overflow:hidden;
padding-left:5px;
background-clip:content-box;
}
.angled-triangle::before {
content:'';
position:absolute;
width:100%;
height:100%;
background-color:white; /*same as element's parent background*/
border-bottom-right-radius: 99% 90%;
left:5px; /*push edge out of element*/
}
在最新的 Chrome 和 Firefox 中测试。根据需要随意调整这些值。
这种方法的唯一缺点是您需要将相同的background-color 应用于::before 作为元素父级的背景,这并不总是可行的(例如body 与背景图像)。检查下面的更新以了解另一种没有此限制的方法。
更新
另一种可行的方法是使用径向渐变背景。与上述方法不同,此方法不会出现任意元素背景的问题,因为此方法使用transparent 颜色填充“空白”区域。
Demo
.angled-triangle {
width:200px;
height:50px;
background-image: -moz-radial-gradient(0 0, transparent 70%, orange 71.5%);
background-image: -webkit-radial-gradient(0 0, transparent 70%, orange 71.5%);
background-image: radial-gradient(top left, transparent 70%, orange 71.5%);
background-position: 5px 0px;
background-repeat:no-repeat;
}
在上面,orange 代表您希望三角形的颜色。透明和橙色之间的1.5% 只是“缓和”,因此边框看起来不会像素化。这缺少 -ms 和 -o 供应商前缀,因为我没有在这些浏览器中测试过。