css设计一个只有轮廓,背景色为透明的五角星,
时间: 2024-03-27 11:40:25 浏览: 22
可以使用 CSS 的伪元素 ::before 和 ::after 来实现一个只有轮廓,背景色为透明的五角星。具体代码如下:
```css
.star {
position: relative;
width: 0;
height: 0;
border-style: solid;
border-width: 0 50px 86.6px 50px;
border-color: transparent transparent #000 transparent;
transform: rotate(35deg);
}
.star::before {
position: absolute;
content: "";
width: 0;
height: 0;
border-style: solid;
border-width: 0 35px 61.0px 35px;
border-color: transparent transparent #fff transparent;
transform: rotate(-35deg);
}
.star::after {
position: absolute;
content: "";
width: 0;
height: 0;
border-style: solid;
border-width: 0 25px 43.3px 25px;
border-color: transparent transparent #000 transparent;
transform: rotate(35deg);
}
```
在 HTML 中,只需要添加一个 class 为 "star" 的 div 即可:
```html
<div class="star"></div>
```
这样就可以实现一个只有轮廓,背景色为透明的五角星了。