A Pen by Hans Spieß on CodePen.
Created
June 25, 2015 15:33
-
-
Save hansspiess/c0b148ce53aeb3d4d786 to your computer and use it in GitHub Desktop.
Skewed full width menu with scss
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
<ul> | |
<li><a href="#">First item</a></li> | |
<li><a href="#">other item</a></li> | |
<li><a href="#">and...</a></li> | |
<li><a href="#">last item!</a></li> | |
</ul> |
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
$height: 200; // default: height of menu | |
$skew-angle: 50; // default: angle | |
@import "compass"; // import compass for easier math functions: http://compass-style.org/reference/compass/helpers/math/#tan | |
$skew-deg: $skew-angle * 1deg; // attach deg unit to force calculation as degree units | |
$a: tan( $skew-deg ) * $height; // calculate opposite leg of triangle | |
body { | |
margin: 0; | |
padding: 0; | |
font: normal small-caps normal 18px/150% Arial, Helvetica, sans-serif; | |
} | |
ul { | |
width: 100%; | |
display: flex; | |
overflow: hidden; // prevent vertical scrollbar | |
margin: 0; | |
padding: 0; | |
list-style: none; | |
li { | |
flex: 1 auto; // distribute children to container size | |
-webkit-transform: skew( $skew-angle * -1deg ); | |
overflow: hidden; // hide overlapping links with negative margins | |
margin: auto; | |
margin-left: -1px; // compensate rendering issues | |
&:first-child { | |
margin-left: $a / 2 * -1px; // negative margins to compensate | |
} | |
&:last-child { | |
margin-right: $a / 2 * -1px; | |
} | |
a { | |
display: block; | |
-webkit-transform: skew( $skew-angle * 1deg ); | |
margin: 0 $skew-angle / 2 * -1em; | |
padding: 0 $skew-angle / 2 * 1em; | |
line-height: $height * 1px; | |
background: red; | |
color: #FFF; | |
text-align: center; | |
text-decoration: none; | |
&:hover { | |
color: red; | |
background-color: #e2e2e2; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment