I know it\'s possible to create a hexagon shape using the following code:
.hex:before {
content: \" \";
width: 0; height: 0;
border-bottom: 30px
Here is another method to create hexagons with border (or outline) using the clip-path feature. In this method, we use a container element and a pseudo-element which has smaller dimensions (both height and width) than the container. When the same clip-path is applied to both the elements, the background-color of the container element is seen behind the pseudo-element only at the edges and makes it look like a border/outline to the shape.
Advantages:
background..hexagon {
position: relative;
height: 150px;
width: 150px;
background: black;
}
.hexagon:before, .double:after {
position: absolute;
content: '';
}
.hexagon:before {
top: 4px; /* border width */
left: 4px; /* border width */
height: calc(100% - 8px); /* 100% - (2 * border width) */
width: calc(100% - 8px); /* 100% - (2 * border width) */
background: #6c6;
}
.hexagon, .hexagon:before, .double:after {
-webkit-clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
}
.image:before {
background: url(http://lorempixel.com/150/150/nature/1);
}
.double:after {
top: 8px;
left: 8px;
height: calc(100% - 16px);
width: calc(100% - 16px);
background: black;
}
/* Just for demo */
.hexagon {
display: inline-block;
margin: 20px;
}
The major disadvantage is the poor browser support at present. CSS clip-path do not work in IE and FF currently. The problem with FF can be fixed by using a SVG (inline or external) for the clip-path (like in the below snippet):
.hexagon {
position: relative;
height: 150px;
width: 150px;
background: black;
}
.hexagon:before, .double:after {
position: absolute;
content: '';
}
.hexagon, .hexagon:before, .double:after {
-webkit-clip-path: url(#hexagon-clip);
clip-path: url(#hexagon-clip);
}
.hexagon:before {
top: 4px; /* border width */
left: 4px; /* border width */
height: calc(100% - 8px); /* 100% - (2 * border width) */
width: calc(100% - 8px); /* 100% - (2 * border width) */
background: #6c6;
}
.image:before {
background: url(http://lorempixel.com/200/200);
}
.double:after {
top: 8px;
left: 8px;
height: calc(100% - 16px);
width: calc(100% - 16px);
background: black;
}
/* Just for demo */
.hexagon {
display: inline-block;
margin: 20px;
}