A cross-browser method using semantic markup and CSS to align list items horizontally and space them evenly so they are distributed across the full available width. Useful for laying out lists of thumbnail images or navigation links for example.
Tested in IE6, IE7, IE8, FF, Safari, Chrome
Fixed Width Content Using This Method:
Variable Width Content:
HTML:
<ul class="block-list"> <li>Content</li> <li>Content</li> <li>Content</li></ul>
CSS:
/* set base font-size (customize to suit) */ body, .block-list li {font-size: 12px;} /* trigger hasLayout in IE */ .block-list, .block-list li {zoom: 1;} .block-list { font-size: 0 !important; /* remove physical spaces between items */ text-align: justify; text-justify: distribute-all-lines; /* distribute items in IE */ list-style-type: none; margin: 0; padding: 0; } /* fully justify all items in browsers other than IE */ .block-list:after { content: ""; display: inline-block; width: 100%; } .block-list li { text-align: left; /* customize to suit */ vertical-align: top; /* can customize to suit */ display: inline-block; width: 31.3%; /* optional, only need for text content to wrap */ margin-bottom: 1em; /* optional, customize to suit */ } /* IE hacks to make li's line up */ *+html .block-list li {display: inline;} * html .block-list li {display: inline;}
IMPORTANT:
There must be no space between the last li tag and the closing ul tag in your HTML markup. This is to fix a bug in Safari so it won’t add extra space after the last list item.