ul { list-style-type: none; overflow: hidden; width:200px; }
ul li { float:left; width: 100px; }
ul li a { display: block; padding: 10px; width:80px; }
ul li a:hover { background: black; }
<ul>
<li><a href="http://www.facebook.com">Facebook</a></li>
<li><a href="httpt://www.google.com">Google</a></li>
</ul>
This is what I prefer mostly because when you use display:inline
you cannot set properties like width, padding (top and bottom), margin etc... which is an handicap for layout purposes.
EDIT 2014
It is also an option to use the display: inline-block
property. One think to note is that once you make the list elements inline or inline-block, white-spaces will be taken into consideration. Hence, there will be unwanted spaces between elements.
ul { list-style-type: none; width: 300px; font-size: 0; }
ul li { display: inline-block; *display: inline; zoom: 1; margin-right: 10px; }
/* The *display and zoom is a IE hack, though can't remember
now which one (guess it is IE7) */
ul li a { display: inline-block; padding: 10px; font-size: 13px; }
Check the fiddle here.
If you don't want to use the font-size
property (for browser compatibility issues), you can also use html comments to get rid off whitespaces! Though I prefer the method above.
<ul><!--
--><li><a href="http://www.facebook.com">Facebook</a></li><!--
--><li><a href="httpt://www.google.com">Google</a></li><!--
--></ul>
display:inline
, because they were not designed for that. Just like giving table cells other display values.float
is what I would go with. – Hindu