Skip to content

Instantly share code, notes, and snippets.

@davidhund
Created February 12, 2013 12:45
Show Gist options
  • Save davidhund/4762637 to your computer and use it in GitHub Desktop.
Save davidhund/4762637 to your computer and use it in GitHub Desktop.
A rotated hexagon with CSS only
/**
* A rotated hexagon with CSS only
*/
body {
background: #f06;
background: linear-gradient(45deg, #CFF, #3FF);
color: #FFF;
min-height: 100%;
}
.hexagon,
.hexagon__inner {
width: 300px;
height: 300px;
padding: 0;
text-align: center;
line-height: 300px;
font-size: 64px;
border-radius: 50%;
}
body:hover .hexagon,
body:hover .hexagon__inner {
border-radius: 20%;
}
.hexagon {
margin: 2em auto;
position: relative;
transform-style: preserve-3d;
transform: rotate(-90deg) rotateY(45deg) rotateX(45deg);
background-color: rgba(0,0,0,0.2);
}
.hexagon__inner
{
display: block;
content: "";
position: absolute;
background: rgba(0,0,0,0.2);
}
.hexagon__inner.one {
-webkit-transform: rotateY(90deg) translateZ(150px);
}
.hexagon__inner.two {
-webkit-transform: translateZ(150px);
}
.hexagon__inner.three {
-webkit-transform: rotateX(90deg) translateZ(150px);
}
.hexagon__inner.four {
-webkit-transform: translateZ(-150px);
}
.hexagon__inner.five {
-webkit-transform: rotateY(90deg) translateZ(-150px);
}
.hexagon__inner.six {
-webkit-transform: rotateX(90deg) translateZ(-150px);
}
<div class="hexagon">
<div class="hexagon__inner one">1</div>
<div class="hexagon__inner two">2</div>
<div class="hexagon__inner three">3</div>
<div class="hexagon__inner four">4</div>
<div class="hexagon__inner five">5</div>
<div class="hexagon__inner six">6</div>
</div>
// alert('Hello world!');
{"view":"split-vertical","fontsize":"100","seethrough":"","prefixfree":"1","page":"all"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment