tags:

views:

76

answers:

2

I'd like to create two column layout for my list using CSS.

Let's say I have 5 items, the presentation would be:

<item 1>  <item 4>
<item 2>  <item 5>
<item 3>

How can I do this with HTML and CSS? Keep in mind that the list length is variable.

I'll be generating the HTML server side using C#, that will provide more flexibility.

+1  A: 

Try this article from AListApart, pretty much covers all the bases

Tom
very nice @tom i was looking for the article but then had to leave it in between
TheVillageIdiot
A: 

I finally made up my mind and use two floated DIVs to achieve this layout.

The server side code will iterate the items and create a new DIV if it passes the halfway point (current index >= half of length).

The resulting HTML would look like the following:

<div class="container">
  <div class="column">
    <div>Item 1</div>
    <div>Item 2</div>
    <div>Item 3</div>
  </div>
  <div class="column">
    <div>Item 4</div>
    <div>Item 5</div>
  </div>
  <div style="clear: both"></div>
</div>

CSS:

.column { float: left; }

The server side will determine when to close and create a new DIV. Not pretty, but it works.

Adrian Godong
And your code would be..? The point of Stackoverflow is to help others by posting code solutions. I'm glad that you were able to answer/solve your own problem, but it'd be nice if you could help out others that might come across the same problem in future =)
David Thomas
Good solution Adrian.And Thomas, seems like you're more angry that you can't just copy/paste his solution. It's pretty self explanatory.
Joe Behymer