「六角形」の描画。borderを使った例とbackgroundを使った例です。
borderを使った例
html
<div class="hexagon"></div>
css
.hexagon { position: relative; width: 100px; height: 50px; background-color: #39a9d6; } .hexagon:before { position: absolute; top: -35px; left: 0; width: 0; height: 0; content: ""; border-left: 50px solid transparent; border-right: 50px solid transparent; border-bottom: 35px solid #39a9d6; } .hexagon:after { position: absolute; bottom: -35px; left: 0; width: 0; height: 0; content: ""; border-left: 50px solid transparent; border-right: 50px solid transparent; border-top: 35px solid #39a9d6; }
backgroundを使った例
html
<div class="hexagon_g"></div>
css
.hexagon_g { width: 100px; height: 170px; background-image: linear-gradient(35deg, transparent 50px, #39a9d6 50px, #2d424f 100%), linear-gradient(-35deg, transparent 50px, #39a9d6 50px, #2d424f 100%), linear-gradient(215deg, transparent 50px, #39a9d6 50px, #2d424f 100%), linear-gradient(-215deg, transparent 50px, #39a9d6 50px, #2d424f 100%); background-position: bottom left, bottom right, top right, top left; background-size: 50% 50%; background-repeat: no-repeat; }
頑張ってみたが微妙・・・
これは使えそうにない。
これは使えそうにない。