Last active
February 1, 2017 13:33
-
-
Save joelstein/df24cdb29b03471f0e5c to your computer and use it in GitHub Desktop.
Horizontal list mixins
This file contains hidden or 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
// Standard horizontal list, using word-spacing trick to remove whitespace | |
// between inline-block elements. | |
@mixin horizontal-list { | |
padding: 0; | |
text-align: center; | |
word-spacing: -1em; | |
display: table; | |
width: 100%; | |
li { | |
display: inline-block; | |
word-spacing: 0; | |
} | |
} | |
// Horizontal list separated by :after content. | |
@mixin horizontal-list-separated($separator:'') { | |
@include horizontal-list; | |
li:not(.last):after { | |
content: $separator; | |
} | |
} | |
// Horizontal list with padded links. | |
@mixin horizontal-list-padded($vertical, $horizontal) { | |
@include horizontal-list; | |
li { | |
padding: $vertical 0; | |
a { | |
padding: $vertical $horizontal; | |
} | |
} | |
} |
This file contains hidden or 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
// To make a horizontal list of any <ul>, just do this: | |
ul.menu { | |
@include horizontal-list(); | |
} | |
// Or, to separate the <li> items by a separator (assuming each <li> contains an <a>): | |
ul.menu { | |
@include horizontal-list-separated("|"); | |
a { | |
padding: 0 10px; | |
} | |
} | |
// Or, to build horizontal list with padded links (probably used for hover effects): | |
ul.menu { | |
@include horizontal-list-padded(5px, 10px); | |
a:hover { | |
background: blue; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment