Skip to content

Instantly share code, notes, and snippets.

@cfxd
Forked from oksushi/dabblet.css
Last active December 20, 2015 10:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cfxd/6119486 to your computer and use it in GitHub Desktop.
Save cfxd/6119486 to your computer and use it in GitHub Desktop.
Tableless horizontal navigation bar with padding and even spacing; no space between elements, no unused container space, and no fixed width (so works for any number of elements!).Fiddle at http://jsfiddle.net/VBcUM/2/
/**
* Using display: table-cell to evenly determine widths. You can add an arbitrary number of <li>
*/
ul {
padding: 0;
display: table;
width: 100%;
table-layout: fixed;
}
li {
display: table-cell;
}
a {
display: block;
padding: 1em;
text-align: center;
background: white;
}
a:hover {
background: lime;
}
<ul>
<li><a href="#">Lorem ipsum</a></li>
<li><a href="#">Dolor</a></li>
<li><a href="#">Sit</a></li>
<li><a href="#">Amet</a></li>
<li><a href="#">Consectetur</a></li>
<li><a href="#">Adipiscing</a></li>
</ul>
ul {
padding: 0;
display: table;
width: 100%;
table-layout: fixed;
li {
display: table-cell;
a {
display: block;
padding: 1em;
text-align: center;
background: white;
&:hover {
background: lime;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment