Is it possible using a standard unordered list with a fixed height, to have overflowing elements flow into the next column.
Essentially I’m trying to achieve a magazine style layout where each article is stacked vertically.
Example code at http://jsfiddle.net/uDAJy/1/
I would expect the list items numbered 2, to be in the next column.
Thanks
Ben
Solution
I’m going to go down the CSS3 route that @Sime posted where possible.
For IE:
As the articles on the page are variable widths I couldn’t find a clean solution without doing some server side programming.
This involved first calculating the number of items per column (forgive the c#):
int itemsPerColumn = Model.Posts.Count / 5; // 5 columns on our page
if (Model.Posts.Count % 5 > 0) {
itemsPerColumn++; // so 8 articles would yield 2 per column
}
We then loop through each article and increment a counter.
If i % itemsPerColumn == 0 we create an opening column div.
After rendering the item we check if (i + 1) % itemsPerColumn == 0 and if so render a closing column div.
Then we increment the counter.
Not quite as nice as the CSS3 solution but it works 🙂
Here you go:
HTML:
CSS:
Live demo: http://jsfiddle.net/uDAJy/5/show/
This should work in all browsers except IE. (I only have Chrome on my notebook, so I can’t test this in the other browsers.)