Created
April 4, 2013 22:43
-
-
Save skopp/5315014 to your computer and use it in GitHub Desktop.
A CodePen by skopp.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="hexrow"> | |
<div> | |
<span>Any text you would like (that fits).</span> | |
<div></div> | |
<div></div> | |
</div> | |
<div> | |
<span>Really, change the text to say what you want!</span> | |
<div></div> | |
<div></div> | |
</div> | |
<div> | |
<span>I'm not kidding here.</span> | |
<div></div> | |
<div></div> | |
</div> | |
<div> | |
<span>Okay?</span> | |
<div></div> | |
<div></div> | |
</div> | |
</div> | |
<div class="hexrow"> | |
<div> | |
<span>Did I mention you can change images? I mean, really, these are just rectangular images "cropped" to a hex shape (well, more complicated than just a crop, but the result is the same).</span> | |
<div></div> | |
<div></div> | |
</div> | |
<div> | |
<span>See, another image!</span> | |
<div></div> | |
<div></div> | |
</div> | |
<div> | |
<span>Testing opacity.</span> | |
<div></div> | |
<div></div> | |
</div> | |
<div> | |
<span>Satisfied?</span> | |
<div></div> | |
<div></div> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// more freakin hexagonz ! /// | |
///http://jsfiddle.net/mqyCb/154/// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
background-color: cyan; | |
} | |
.hexrow { | |
white-space: nowrap; | |
/*right/left margin set at (( width of child div x sin(30) ) / 2) makes a fairly tight fit; a 3px bottom seems to match*/ | |
margin: 0 25px 3px; | |
} | |
.hexrow > div { | |
width: 100px; | |
height: 173.2px; /* ( width x cos(30) ) x 2 */ | |
/* For margin: | |
right/left = ( width x sin(30) ) makes no overlap | |
right/left = (( width x sin(30) ) / 2) leaves a narrow separation | |
*/ | |
margin: 0 25px; | |
position: relative; | |
background-image: url(http://i1166.photobucket.com/albums/q605/Artem_Lebedev/dog-training-collars.jpg); | |
background-position: -50px 0; /* -left position -1 x width x sin(30) */ | |
background-repeat: no-repeat; | |
background-size: auto 120%; | |
color: #000000; | |
text-align: center; | |
line-height: 173.2px; /*equals height*/ | |
display: inline-block; | |
} | |
.hexrow > div:nth-child(odd) { | |
top: 43.3px; /* ( width x cos(30) / 2 ) */ | |
} | |
.hexrow > div:nth-child(even) { | |
top: -44.8px; /* -1 x( ( width x cos(30) / 2) + (hexrow bottom margin / 2)) */ | |
} | |
.hexrow > div > div:first-of-type { | |
position: absolute; | |
width: 100%; | |
height: 100%; | |
top: 0; | |
left: 0; | |
z-index: -1; | |
overflow: hidden; | |
background-image: inherit; | |
-ms-transform:rotate(60deg); /* IE 9 */ | |
-moz-transform:rotate(60deg); /* Firefox */ | |
-webkit-transform:rotate(60deg); /* Safari and Chrome */ | |
-o-transform:rotate(60deg); /* Opera */ | |
transform:rotate(60deg); | |
} | |
.hexrow > div > div:first-of-type:before { | |
content: ''; | |
position: absolute; | |
width: 200px; /* width of main + margin sizing */ | |
height: 100%; | |
background-image: inherit; | |
background-position: 0 0; | |
background-repeat: no-repeat; | |
background-size: auto 120%; | |
bottom: 0; | |
left: 0; | |
z-index: 1; | |
-ms-transform:rotate(-60deg) translate(-150px, 0); /* IE 9 */ | |
-moz-transform:rotate(-60deg) translate(-150px, 0); /* Firefox */ | |
-webkit-transform:rotate(-60deg) translate(-150px, 0); /* Safari and Chrome */ | |
-o-transform:rotate(-60deg) translate(-150px, 0); /* Opera */ | |
transform:rotate(-60deg) translate(-150px, 0); | |
-ms-transform-origin: 0 0; /* IE 9 */ | |
-webkit-transform-origin: 0 0; /* Safari and Chrome */ | |
-moz-transform-origin: 0 0; /* Firefox */ | |
-o-transform-origin: 0 0; /* Opera */ | |
transform-origin: 0 0; | |
} | |
.hexrow > div > div:last-of-type { | |
content: ''; | |
position: absolute; | |
width: 100%; | |
height: 100%; | |
top: 0; | |
left: 0; | |
z-index: -2; | |
overflow: hidden; | |
background-image: inherit; | |
-ms-transform:rotate(-60deg); /* IE 9 */ | |
-moz-transform:rotate(-60deg); /* Firefox */ | |
-webkit-transform:rotate(-60deg); /* Safari and Chrome */ | |
-o-transform:rotate(-60deg); /* Opera */ | |
transform:rotate(-60deg); | |
} | |
.hexrow > div > div:last-of-type:before { | |
content: ''; | |
position: absolute; | |
width: 200px; /* starting width + margin sizing */ | |
height: 100%; | |
background-image: inherit; | |
background-position: 0 0; | |
background-repeat: no-repeat; | |
background-size: auto 120%; | |
bottom: 0; | |
left: 0; | |
z-index: 1; | |
/*translate properties are initial width (100px) and half height (173.2 / 2 = 86.6) */ | |
-ms-transform:rotate(60deg) translate(100px, 86.6px); /* IE 9 */ | |
-moz-transform:rotate(60deg) translate(100px, 86.6px); /* Firefox */ | |
-webkit-transform:rotate(60deg) translate(100px, 86.6px); /* Safari and Chrome */ | |
-o-transform:rotate(60deg) translate(100px, 86.6px); /* Opera */ | |
transform:rotate(60deg) translate(100px, 86.6px); | |
-ms-transform-origin: 100% 0; /* IE 9 */ | |
-webkit-transform-origin: 100% 0; /* Safari and Chrome */ | |
-moz-transform-origin: 100% 0; /* Firefox */ | |
-o-transform-origin: 100% 0; /* Opera */ | |
transform-origin: 100% 0; | |
} | |
.hexrow > div > span { | |
display: inline-block; | |
margin: 0 -30px; | |
line-height: 1.1; | |
vertical-align: middle; | |
white-space: normal; | |
} | |
.hexrow:nth-child(2) > div:nth-child(1) { | |
background-image: url(http://i724.photobucket.com/albums/ww244/NBAchikk1995/flowers.jpg); | |
} | |
.hexrow:nth-child(2) > div:nth-child(1) > span { | |
/*change some other settings*/ | |
margin: 0 -20px; | |
color: black; | |
font-size: .8em; | |
font-weight: bold; | |
} | |
.hexrow:nth-child(2) > div:nth-child(2) { | |
background-image: url(http://i197.photobucket.com/albums/aa231/sterling_red/landscape.jpg); | |
color: #ffffff; | |
} | |
.hexrow:nth-child(2) > div:nth-child(3) { | |
background-image: url(http://i257.photobucket.com/albums/hh204/h22prld98/2157781306_7a7a8e4cf7.jpg); | |
opacity: .3; | |
color: #ffffff; | |
} | |
.hexrow:nth-child(2) > div:nth-child(3) > div:before { | |
/* nothing special needed here */ | |
} | |
.hexrow:nth-child(2) > div:nth-child(4) { | |
background-image: url(http://i916.photobucket.com/albums/ad8/paulak100/Obraz395.jpg); | |
/*you can shift a large background image, but it can get complicated | |
best to keep the image as the total width (200px) and height (174px) | |
that the hex would be. | |
*/ | |
background-position: -150px -20px; | |
} | |
.hexrow:nth-child(2) > div:nth-child(4) > div:before { | |
background-position: -100px -20px; /* the left shift is always less in the pseudo elements by the amount of the base shift */ | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment