CSS blues

Date November 25, 2007

So I’m back to the CSS blues I encounter every time I try to follow the ‘web standards’ crowd. I’ve got a relatively straightforward problem which is solved with using tables to arrange images, but seems utterly broken trying to use tableless CSS. Perhaps someone here will set me straight.

I am displaying search results - thumbnail images and text. Putting each set of data in a div tag with a class that has a float:left in it allows me to just keep rendering the image/text combos, and the browser will wrap the data accordingly. Except that the float:left behaviour will float the data to the left not to the ‘beginning’ of where the first element started, but only as far left as it needs to to determine it’s ‘hit’ something. Hard to explain in English, but the screenshot below should give an idea. The two items on the bottom row should be flush left, but they’re not. The first result image has text which is a bit more than the rest on that row, so it ‘blocks’ the 7th result item from floating any further left.

  moc_screen1.png

Searching around for the answer has yielded nothing that matches my requirements:

1. I want to be able to change the size of the items and data being displayed without having to know in advance how many will fit on a row.

Well, that’s really about it. To be fair, even in a table situation, you have to know how many you’ll be displaying, then close and reopen a TR tag. Given the supposed ’superior’ nature of CSS, I’d have figured this problem would have been solved. I can also issue a div with a clear:both style after every 6 results, but that’s a hack answer, in my view.

Any better solutions? Google images uses tables to show their results - that should send a message to all those “tableless design at all costs” nuts out there (message being “css still isn’t ready enough to bury tables yet”) but it won’t.

 Did you like this post? Buy me a hot chocolate!

5 Responses to “CSS blues”

  1. s said:

    I think I understand the problem, but putting something like a “border:1px solid red;” on the div would make it easier to see.

    Only thing I can think of right now is to make the divs a fixed height (and then “overflow:none or auto”). Even then, I’m not sure if it would be cross-browser-safe

    Still not as good as a TRs automatic height adjustment :(

    Will give it some more thought. If you come up with a workable solution I’d sure like to hear about it.

  2. Rob Wultsch said:

    I suggest figuring out a max height you will allow, setting a css attribute on the div, and truncating text if it would likely exceed the limit.

  3. mgkimsal said:

    Thanks Rob:

    That is an option which I might have to go to, or revert back to tables. I don’t necessarily know ahead of time how much text I will have, nor would I be able to guarantee how many lines it would take up, even by character count (yes, I know I can estimate some). I just wish there was an easier way of dealing with this.

  4. Dustin Brewer said:

    I would first suggest that rather then using divs, you should use a list to do what you are wanting. Just make sure you set list-style: none and display: inline for the list (as well as float: left).

    Once you have done that set a width and some margin to allow for the list’s items to be spaced out from each other evenly to the right/left and bottom.

    This should fix your problem.

    (i also wrote an article that should help you and anyone else with this issue, it should post at 8am CDT)

  5. Bill Robertson said:

    http://www.stylemob.com

    Thought you would want to check this site out if you already hadn’t.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">