This is a quick, simple tutorial on how to create multiple column lists by only using one ul. Often is the case when you’d want multiple lists side-by-side, but you end up using markup like <ul class="col"> in order to get several lists sat next to each other. However, by simply floating lis left and setting their width to the correct percentage (two columns = li{width:50%;} and so on), you can attain a multiple column list pretty easily.
View demo
The trick here is to force the list to break at the right point. If you want two columns, you need to float the list items left and set them at 50% width, therefore the list items will only ever fit two side-by-side, then begin again on the row beneath. By that token, three columns would require a width of 33% and floated left, four would be 25% and so on.
The code
Both the markup and CSS for this is incredibly simple, nothing fancy, no CSS3, nothing progressive, just basic styling applied to lean markup.
The markup
The markup for this is just a simple ul, thus:
<ul id="double"> <!-- Alter ID accordingly -->
<li>CSS</li>
<li>XHTML</li>
<li>Semantics</li>
<li>Accessibility</li>
<li>Usability</li>
<li>Web Standards</li>
<li>PHP</li>
<li>Typography</li>
<li>Grids</li>
<li>CSS3</li>
<li>HTML5</li>
<li>UI</li>
</ul>
And to make this into a multiple column list:
ul{
width:760px;
margin-bottom:20px;
overflow:hidden;
border-top:1px solid #ccc;
}
li{
line-height:1.5em;
border-bottom:1px solid #ccc;
float:left;
display:inline;
}
#double li { width:50%;} /* 2 col */
#triple li { width:33.333%; } /* 3 col */
#quad li { width:25%; } /* 4 col */
#six li { width:16.666%; } /* 6 col */
When to use this
Use this wisely… It displays content in an ambiguous manner and should not be used where order of reading is imperative.
This method should only be used if the lists content doesn’t require any specific ordering as the markup is written linearly and the list is displayed in a matrix. As you can see, the way the content is displayed means it can be read across»down»across or down»up»down. This means that the way you write your content is not necessarily the way it will be read. In my example this isn’t an issue, as the content can safely be read in any order.
+
Thursday, February 11th, 2010 in Web Development.
brett said on 14 February, 2010 at 6:12 pm
thank you,
i’d been thinking that there must be a way to show tables in a simpler way….but could never find the way out….
the markup with ul li is better than using tables and i’d implement it hence forth in my web dev. projects for simple tables….
thanks a lot
regards,
brett a.k.a. bharat khiani (freelance web developer).
Harry Roberts said on 15 February, 2010 at 9:13 am
Hi Brett,
I’d sincerely recommend against using lists to layout tables, as per http://csswizardry.com/2009/12/typographic-work-planner/comment-page-1/#comment-30
Harry
Andrzej O. said on 15 February, 2010 at 12:48 pm
This is so simple that I never thought that someone may not know that :-)
But if you want to put tabelar data then you should use tables if you prefer to be semantic in 100%.
viktor said on 15 February, 2010 at 1:08 pm
http://www.csshrou.sk/x-stlpcovy-zoznam-s-jedinym-olul-tagom/
Burton Haynes said on 26 February, 2010 at 5:04 am
I am a huge fan of everything related to typography, keep up the good work
Hudson said on 28 May, 2010 at 2:45 pm
This is so simple, so perfect!
I’m looking to do this with nested uls, preferably without using negative margins to keep the left side flush.
Any suggestions?