【发布时间】:2019-11-12 10:34:24
【问题描述】:
我已经在 HTML 和 CSS 中创建了这颗星,但我正在尝试将它变成一个元素。 这是我目前所拥有的:
.star{
margin:22px auto;left:0;right:0;
width: 0px;
height: 0px;
border-right: 20px solid transparent;
border-bottom: 14px solid #e74c3c;
border-left: 20px solid transparent;
position: absolute;
transform: rotate(35deg);
}
.star-2 {
position: absolute;
display: block;
top: 0px;
left: -20px;
width: 0px;
height: 0px;
border-right: 20px solid transparent;
border-bottom: 14px solid #e74c3c;
border-left: 20px solid transparent;
transform: rotate(-70deg);
}
.star-3{
box-sizing:border-box;
border-bottom: 15px solid #e74c3c;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
position: relative;
height: 0;
width: 0;
top: -10px;
left: -12px;
display: block;
transform: rotate(-35deg);
}
<div class="star">
<div class="star-2">
</div>
<div class="star-3">
</div>
</div>
我是否可以将所有这些都变成一个元素,例如 <div class="star"></div>,仅此而已?
【问题讨论】:
-
总有★或☆
-
CSS 剪辑路径提供了一个多边形选项:developer.mozilla.org/en-US/docs/Web/CSS/clip-path,如 lab.iamvdo.me/css-svg-masks 所示