【发布时间】:2016-08-09 22:28:04
【问题描述】:
【问题讨论】:
标签: css css-shapes rounded-corners
【问题讨论】:
标签: css css-shapes rounded-corners
是的,可以通过使用两个伪元素来实现这个效果。我们需要将一个伪元素相对于容器的左侧定位,而另一个伪元素相对于容器的右侧定位。然后通过在它们上以相反的方向添加transform: skew() 并将边框半径分配给所需的边,我们可以获得所需的输出。
div {
position: relative;
height: 50px;
width: 100%;
padding-top: 50px;
background: blue;
background-clip: content-box;
/* make sure blue background doesn't appear behind triangle */
overflow: hidden;
color: white;
}
div:before,
div:after {
position: absolute;
content: '';
top: 0;
width: calc(50% + 10px);
/* don't change */
height: 50px;
/* must be equal to padding-top */
background: blue;
}
div:before {
left: 0;
transform: skew(45deg);
transform-origin: right bottom;
border-top-right-radius: 12px;
}
div:after {
right: 0;
transform: skew(-45deg);
transform-origin: left bottom;
border-top-left-radius: 12px;
}
<div class='shape'>This is a shape.</div>
【讨论】: