I found a great stackoverflow answer on how to create a hexagonal patten using CSS.
Generate repeating hexagonal pattern with CSS3
It’s almost perfect, except i’d like to flip the hexagons the other way (ie. so the point is at the top). I’ve managed to do this fairly easily by swapping the main hex div width/height: (hexrow > div)… however i’m really struggling to re-align the background image on the other supporting divs. I’ve been trying to figure it out for a while now without much success.
Could anyone possibly post a jsFiddle that shows how it’s done?
This is where i’m at currently: What i’ve tried
..and i believe this is what i need to amend:
.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: 120% auto;
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;
}
Any help much appreciated.
Use
:nth-of-type(odd)and:nth-of-type(even)and set different margins for odd/ even hexagons on the same row.Or you could do it in a much simpler manner, with less markup – check my answer at that question and this demo I just did. The idea is that you apply a series of transforms on the element (which has
overflow: hidden) in order to get a rhombus with an acute angle of60 degreesand then you undo all those transforms in reverse order for a pseudo-element or a child element if you wish (having the sameheightas the element itself, but only.866of itswidth, because .866 is the ratio of the distance between two parallel sides of a hexagon and its big diagonal) on which you actually apply thebackground-image. So there’s no chance of misalignment, because the background image is only applied on one element.Basic HTML structure:
Relevant CSS: