国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > CSS > 正文

css畫正六邊形的兩種方法

2024-07-11 08:25:19
字體:
供稿:網(wǎng)友

說下兩種css 制作正六邊形的方法。

先看一下結(jié)果:

在之前要先了解一下正六邊形內(nèi)角和邊的關(guān)系,正六邊形的每個(gè)內(nèi)角是60deg,如圖(√3其實(shí)是根號(hào)3):

方法一:原理把正六邊形分成三部分,左中右分別是:before部分,div部分,after部分,如圖:

before三角形部分是div的before偽元素,after三角形部分是div的after偽元素。

html代碼:

<div class='div'></div>

css代碼:

.div { position: relative; width: 50px; height: 86.6px; margin: 50px auto; background-color: red; } .div:before { content: ''; display: block; position: absolute; width: 0; height: 0; right:50px; border-width: 43.3px 25px; border-style: solid; border-color: transparent red transparent transparent; } .div:after { content: ''; display: block; position: absolute; width: 0; height: 0; left:50px; border-width: 43.3px 25px; border-style: solid; border-color: transparent transparent transparent red; top:0; }

注意div及偽元素的寬高需要根據(jù)上面的公式計(jì)算。

方法二:也是把正六邊形分成三個(gè)寬高相同的div,然后使用定位以及css3 transform:rotate分別向左右旋轉(zhuǎn)60deg形成正六邊形,如圖:

html代碼:

<div class='div-2'> <div class='one'></div> <div class='two'></div> <div class='three'></div></div>

css代碼:

.one { width: 50px; height: 86.6px; margin: 0 auto; border-top: 1px solid red; border-bottom: 1px solid red; } .two { position: absolute; width: 50px; height: 86.6px; left: 25px; top: 0; transform: translate(-50%,-50%); transform: rotate(60deg); border-top: 1px solid red; border-bottom: 1px solid red; } .three { position: absolute; width: 50px; height: 86.6px; left: 25px; top: 0; transform: translate(-50%,-50%); transform: rotate(300deg); border-top: 1px solid red; border-bottom: 1px solid red; }
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 柳江县| 临洮县| 河南省| 青河县| 长沙市| 江城| 蒙城县| 介休市| 福泉市| 巴南区| 称多县| 山阳县| 旬邑县| 松原市| 原平市| 桦川县| 灯塔市| 玉树县| 溆浦县| 苗栗县| 织金县| 利津县| 大埔区| 台东市| 万年县| 海原县| 奈曼旗| 贡山| 石柱| 盐津县| 施甸县| 永仁县| 方山县| 华蓥市| 绥江县| 前郭尔| 巴彦淖尔市| 出国| 五台县| 宾川县| 宝山区|