Single-div perfect CSS hexagons using :before, :after, transform and calc()
Single-div perfect CSS hexagons using :before, :after, transform and calc()
HTML
<div id="demo">
<div class="contactNav">
<ul>
<li>
<a id="firstButton" href="#">
<div id="hex2" class="hexagon-wrapper">
<div id="color2" class="hexagon"></div>
</div>
<span id="firstSpan">Contact Info
<p>This is our stuff about budget. This is our stuff about budget. This is our stuff about budget. This is our stuff about budget.</p></span>
</a>
</li>
<li>
<a id="secondButton" href="#">
<div id="hex2" class="hexagon-wrapper">
<div id="color2" class="hexagon"></div>
</div>
<span>Budget
<p>This is our stuff about budget. This is our stuff about budget. This is our stuff about budget. This is our stuff about budget.</p></span>
</a>
</li>
<li>
<a id="thirdButton" href="#">
<div id="hex2" class="hexagon-wrapper">
<div id="color2" class="hexagon"></div>
</div>
<span>Timeline
<p>This is our stuff about budget. This is our stuff about budget. This is our stuff about budget. This is our stuff about budget.</p></span>
</a>
</li>
</ul>
</div>
</div>
<!-- Prefixfree.js allows you to write prefix-free CSS
This means no -webkit-transform, -moz-transform, ... -->
<script src="//cdn.jsdelivr.net/prefixfree/1.0.7/prefixfree.min.js"></script>
CSS
body {
background: #333;
}
#hex2 {
width: 150px;
height: 150px;
-ms-transform: rotate(30deg); /* IE 9 */
-webkit-transform: rotate(30deg); /* Chrome, Safari, Opera */
transform: rotate(30deg);
}
#color2 {
background-color: #93D;
}
.hexagon-wrapper {
text-align: center;
margin: 20px;
position: relative;
display: inline-block;
}
.hexagon {
height: 100%;
width: calc(100% * 0.57735);
display: inline-block;
}
.hexagon:before {
position: absolute;
top: 0;
right: calc((100% / 2) - ((100% * 0.57735) / 2));
background-color: inherit;
height: inherit;
width: inherit;
content: '';
transform: rotateZ(60deg);
}
.hexagon:after {
position: absolute;
top: 0;
right: calc((100% / 2) - ((100% * 0.57735) / 2));
background-color: inherit;
height: inherit;
width: inherit;
content: '';
transform: rotateZ(-60deg);
}
.contactNav ul li{
height: 20em;
}
.contactNav ul {
list-style: none; overflow: hidden; position: relative;
}
.contactNav ul li {
float: left; margin: 0 60px 0 0;
}
.contactNav ul li a {
display: block;
background-image: url(icons.png); background-repeat: no-repeat;
}
.contactNav ul li a span {
font: 50px "Dosis", sans-serif; text-transform: uppercase;
position: absolute; left: 36px; top: 120px;
display: inline;
}
.contactNav ul li a:hover span {
display: inline;
}
.contactNav ul li:nth-child(1) a span {
color: #5bb2fc;
}
.contactNav ul li:nth-child(2) a span {
color: #58ebd3;
}
.contactNav ul li:nth-child(3) a span {
color: #ffa659;
}
.contactNav ul li:nth-child(4) a span {
color: #ff7a85;
}
span {
margin-top: 60px;
}
p {
line-height: 0;
font-size: 13px;
}
JavaScript
$(document).ready(function() {
$('.contactNav ul li:nth-child(2) a span').hide();
$('.contactNav ul li:nth-child(3) a span').hide();
$('#firstButton').click(function(e) {
$('.contactNav ul li:nth-child(1) a span').show();
$('.contactNav ul li:nth-child(2) a span').hide();
$('.contactNav ul li:nth-child(3) a span').hide();
e.preventDefault();
})
$('#secondButton').click(function(e) {
$('.contactNav ul li:nth-child(2) a span').show();
$('.contactNav ul li:nth-child(1) a span').hide();
$('.contactNav ul li:nth-child(3) a span').hide();
e.preventDefault();
})
$('#thirdButton').click(function(e) {
$('.contactNav ul li:nth-child(3) a span').show();
$('.contactNav ul li:nth-child(1) a span').hide();
$('.contactNav ul li:nth-child(2) a span').hide();
e.preventDefault();
})
})