tags:

views:

1131

answers:

4

Is there a way to do re-flowable, multi-column lists, where the list can have list items of varying heights, using only valid CSS? By re-flowable, I mean that as the user drags the window wider or narrower, the number of columns should automatically adjust when the list items are of fixed width.

I've seen the article on A List Apart, but none of their solutions fit all of those (seemingly simple) requirements. At first glance, I think the CCS3 proposal for multi-column lists does not either (because it appears you have to specify the number of columns).

If it helps, I am not at all concerned about IE6 and only kind of concerned about IE7. My target audience is early-adopter, web-savvy types.

Update: Looking more closely at the CSS3 spec, specifying a column width should do it, but in reality, I'm running into weirdness with overflows and such. Anyone using this stuff IRL?

A: 

Not through plain CSS, no. There might be a JavaScript implementation somewhere, but I don't know of any fluid ones as you describe.

musicfreak
If browser support is there for the CSS3 module, I could use JS to change the number of columns at pre-determined widths. I'd prefer to avoid that route, though. Not even sure if the browser support is there.
Andrew Hedges
Firefox and WebKit (Safari and Chrome) support it. The problem is, how would you do that? I guess you could edit the .style property of the element, but that's just messy.
musicfreak
Hence my question. :-)
Andrew Hedges
Hmm, I'll think about it and get back to you. Would be an interesting script to write. :)
musicfreak
Sorry, had to vote down since I found the clear CSS3 command supported by Safari and Firefox.
ilya n.
Oh wow, I didn't know about column-width. My mistake!
musicfreak
+5  A: 

Original post

In fact the single command does the trick for me (although it comes in -webkit- and -moz- versions):

div.wrapper 
{
    -webkit-column-width: 10em;
    -moz-column-width: 10em;
}

Here are additional rules to improve readability. Insert the code below and above into an example from A List Apart article (I can paste the whole HTML if somebody clears copyright) and enjoy:

div.wrapper {       
    border: 2px solid blue;
    -webkit-column-rule: 2px solid blue;
    -moz-column-rule: 2px solid blue;
}

.wrapper ol {
    margin: 0;
}

.wrapper br {
    display: none; /* Extra BR is unnecessary there */
}

Tested: Safari 4 (4528.17), Fx 3.5b4 /Mac.

Note that on the first encounter of column-width properties some time ago I completely missed the crucial fact that it does rebalancing. Discovered it now at W3C and confirmed with Surfin' Safari.

Addendum: Fixed number of columns

As I understand from the clarification, the width of columns should change with the widthof the page, so the commands are more like

div.wrapper 
{
    -webkit-column-count: 3;
    -moz-column-count: 3;
}

Addendum: Vertical scrolling

Now you say that there should be a vertical scrollbar. Since there is no UI that would do separate scrollbars to the right of each column, I think you have in mind one scrollbar that would scroll the whole multicolumn list. That can be done by wrapping one more div with

div.morewrap 
{
     height: 50%; /* whatever you need */
     overflow-y: scroll; 
}
ilya n.
I did experiment with setting column widths. It *should* be all I need, but I'm finding with overflow: auto (which I have set because the container is an absolutely positioned div) it just adds columns rather than vertically scrolling. Not what I expected!
Andrew Hedges
I'm not sure what you need. Do you say the whole thing should have both fixed height and width and vertical scrolling if necessary?
ilya n.
In my design, the height and width change with the browser window and I want only vertical scrolling. Safari and Firefox both render with horizontal scrolling (adding columns) the way I have things set up.
Andrew Hedges
I wasn't clear in my previous comment. The viewport size can change, but the column width should remain constant (always 240px in my case). The number of columns should change depending on the viewport width, with only vertical scrolling, if necessary. Does that make sense?
Andrew Hedges
It appear to me that what you need is th combination of "original post" and "Vertical scrolling" sections. Does it work?Note there should only be overflow-y to get the required behavior.
ilya n.
A: 

I've used it for multi-column content layouts, and at the time, emulating the behaviour with javascript in IE was a total pain.

In the end we simply cut up the lists on the server side for consistency. :(

garrow
A: 

I realize this is an old post, but I just got this working on my project, and Ilya's solution did not work for me (though maybe I missed something). Anyway, the problem is that with CSS3 columns (now a Candidate Recommendation) the overflow wants to go off to the right by creating additional columns, and if you have overflow:auto you end up with a horizontal scrollbar, instead of a vertical one (which the OP wanted, and I also wanted). I fixed this by wrapping the div that held the columns (with -moz-column-count set) inside another div, and setting the height on that one with overflow-y:auto. The meant that the outer div could scroll vertically, while the inner div with the columns had as much height as it needed and did not need to overflow horizontally.

I hope the helps.

Paul Lynch