需要.diamond-parent用积木铺设空间.diamond。或者,您可以制作一个 png 图像并将其与背景平铺,但通过 CSS 解决方案很有趣。
.diamond-parent {
width: 300px;
height: 300px;
background: lightpink;
}
.diamond {
width: 0;
height: 0;
border: 30px solid transparent;
border-bottom-color: red;
position: relative;
top: -30px;
}
.diamond:after {
content: '';
position: absolute;
left: -30px;
top: 30px;
width: 0;
height: 0;
border: 30px solid transparent;
border-top-color: red;
}
<div class="diamond-parent">
<div class="diamond"></div>
<div class="diamond"></div>
</div>
您可以使用两个渐变来做到这一点:
小记:
我使用
0两个渐变步长以避免重复之前的值,因为根据规范,渐变步长不能小于之前的值。他们谈论过
png,但svg没有人谈论 =)))