Skip to content

Instantly share code, notes, and snippets.

@wesley6j
Forked from bjmiller121/sass-hexagon.scss
Created February 14, 2016 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wesley6j/ef4d18b67c2462081c8e to your computer and use it in GitHub Desktop.
Save wesley6j/ef4d18b67c2462081c8e to your computer and use it in GitHub Desktop.
SASS Mixin to generate a hexagon in CSS
// Makes a CSS hexagon! based off of http://csshexagon.com/
// Demo: http://sassmeister.com/gist/98fcf3ce163a97d2ef7e
@mixin hexagon($size, $color, $border: 0) {
position: relative;
width: $size;
height: ($size * 0.577);
background-color: $color;
margin: ($size * 0.288) 0;
border-left: $border;
border-right: $border;
&:before,
&:after {
content: "";
position: absolute;
@if $border == 0 {
width: 0;
left: 0;
border-left: ($size/2) solid transparent;
border-right: ($size/2) solid transparent;
} @else {
z-index: 1;
width: ($size * 0.707);
height: ($size * 0.707);
-webkit-transform: scaleY(0.5774) rotate(-45deg);
-ms-transform: scaleY(0.5774) rotate(-45deg);
transform: scaleY(0.5774) rotate(-45deg);
background-color: inherit;
left: ($size * 0.129);
}
}
&:before {
@if $border == 0 {
bottom: 100%;
border-bottom: ($size * 0.288) solid $color;
} @else {
top: -($size * 0.353);
border-top: $border;
border-right: $border;
}
}
&:after {
@if $border == 0 {
top: 100%;
width: 0;
border-top: ($size * 0.288) solid $color;
} @else {
bottom: -($size * 0.353);
border-bottom: $border;
border-left: $border;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment