【JS提升】六边形的两种画法

一、六边形的两种画法

(1)画法一

.hexagon-1 {
    position: relative;
    width: 100px;
    /* 思考这里的高的怎么求的 */
    height: 173.2px;
    margin: 0 auto;
    background-color: red;
}
.hexagon-1::before,
.hexagon-1::after {
    content: "";
    display: block;
    position: absolute;
    top: 0;
    width: 0;
    height: 0;
    border-top: 86.6px solid transparent;
    border-bottom: 86.6px solid transparent;
}
.hexagon-1::before {
    left: -50px;
    border-right: 50px solid green;
}
.hexagon-1::after {
    right: -50px;
    border-left: 50px solid green;
}

在这里插入图片描述

(2)画法二

.hexagon-2 {
    position: relative;
    width: 100px;
    height: 173.2px;
    margin: 0 auto;
    background-color: red;
}
.hexagon-2::before,
.hexagon-2::after {
    content: "";
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 100px;
    height: 173.2px;
}
.hexagon-2::before {
    transform: rotate(60deg);
    background-color: green;
}
.hexagon-2::after {
    transform: rotate(-60deg);
    background-color: purple;
}

(3)画法三

.hexagon-3 {
    position: relative;
    width: 100px;
    height: 173.2px;
    margin: 0 auto;
    /* background-color: red; */
    border-top: 1px solid #000;
    border-bottom: 1px solid #000;
    box-sizing: border-box;
}
.hexagon-3::before,
.hexagon-3::after {
    content: "";
    display: block;
    position: absolute;
    top: -1px;
    left: 0;
    width: 100px;
    height: 173.2px;
    box-sizing: border-box;
}
.hexagon-3::before {
    transform: rotate(60deg);
    /* background-color: green; */
    border-top: 1px solid #000;
    border-bottom: 1px solid #000;
}
.hexagon-3::after {
    transform: rotate(-60deg);
    /* background-color: purple; */
    border-top: 1px solid #000;
    border-bottom: 1px solid #000;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值