用css画五角星

原理是:三个三角形,其中两个等边三角形交叉出4个角,叠加第三个三角形,形成5角,代码如下:

<span class="star"></span>
.star {
    position: relative;
    width: 0;
    height: 0;
    border-right: 3px solid transparent;
    border-bottom: 8px solid #888888;
    border-left: 3px solid transparent;
    transform: rotate(35deg);
    &:hover {
      border-bottom-color: #b32620;
      &::before {
        border-bottom-color: #b32620;
      }
      &::after {
        border-bottom-color: #b32620;
      }
    }
  }
  .star:before {
    content: "";
    position: absolute;
    top: 23.7px;
    left: -10.4px;
    width: 0;
    height: 0;
    border-right: 10px solid transparent;
    border-bottom: 7px solid #888888;
    border-left: 10px solid transparent;
    transform: rotate(-36deg);
  }
  .star:after {
    content: "";
    position: absolute;
    top: 23.7px;
    left: -8.4px;
    width: 0;
    height: 0;
    border-right: 10px solid transparent;
    border-bottom: 7px solid rgba(136, 136, 136, 1);
    border-left: 10px solid transparent;
    transform: rotate(35deg);
  }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我分别为您回答如下: 1. HTML CSS 五角星 HTML结构: ```html <div class="star"></div> ``` CSS样式: ```css .star { width: 0; height: 0; border-right: 50px solid transparent; border-bottom: 35px solid #f1c40f; border-left: 50px solid transparent; position: relative; top: -10px; } .star:before { content: ""; width: 0; height: 0; border-right: 50px solid transparent; border-bottom: 35px solid #f1c40f; border-left: 50px solid transparent; position: absolute; top: -25px; left: -50px; transform: rotate(35deg); } .star:after { content: ""; width: 0; height: 0; border-right: 50px solid transparent; border-bottom: 35px solid #f1c40f; border-left: 50px solid transparent; position: absolute; top: -25px; left: 0; transform: rotate(-35deg); } ``` 2. CSS 梯形 HTML结构: ```html <div class="trapezoid"></div> ``` CSS样式: ```css .trapezoid { border-bottom: 100px solid #f1c40f; border-left: 50px solid transparent; border-right: 50px solid transparent; height: 0; width: 100px; } ``` 3. CSS 六角星 HTML结构: ```html <div class="hexastar"></div> ``` CSS样式: ```css .hexastar { width: 0; height: 0; border-bottom: 50px solid #f1c40f; border-left: 29px solid transparent; border-right: 29px solid transparent; position: relative; } .hexastar:before { content: ""; width: 0; height: 0; border-top: 50px solid #f1c40f; border-left: 29px solid transparent; border-right: 29px solid transparent; position: absolute; top: -50px; left: -29px; } ``` 4. CSS 六边形 HTML结构: ```html <div class="hexagon"></div> ``` CSS样式: ```css .hexagon { width: 100px; height: 55px; background-color: #f1c40f; position: relative; } .hexagon:before, .hexagon:after { content: ""; position: absolute; z-index: 1; width: 0; border-left: 50px solid transparent; border-right: 50px solid transparent; } .hexagon:before { bottom: 100%; border-bottom: 28px solid #f1c40f; } .hexagon:after { top: 100%; width: 0; border-top: 28px solid #f1c40f; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值