It seems I was a little unclear in my recent post about floats, and compounded the problem with the post title. A number of responses said, basically, “maybe they’re bad for layout but what else is available?” I didn’t mean to suggest that nobody should use floats for layout, or that using them in that manner is somehow wrong; my apologies if I did so. There aren’t too many alternatives; in fact, there are precisely three general standards-based layout options.
Each of these options has its benefits and drawbacks. All I was trying to say is that Andrei was dead on in his feeling that layout floats feel like something that have been bent to a purpose for which they weren’t intended. That’s true. Floats are simple, and were meant to do a very limited thing. Push them hard enough into other roles, and they become a touch balky. If nothing else, their source-order dependencies make them less flexible than one might like, and variances in browser handling of floats (many of those variances having to do with how one should deal with floats in their intended role) just makes the situation more frustrating.
One could argue that all three options are non-layout technologies that have been bent to layout purposes, but positioning at least was intended to be a layout mechanism from its inception. It suffers from enough glaring flaws and browser bugs that it can’t be considered any better an option than the others, though.
In a move that may help matters, Shaun Inman (he of the Inman Flash Replacement technique) has just published the article Clearing Absolutes Again, which further develops his attempts to give positioned elements a
clear-like capability. This is a very welcome development. The IPC (Inman Position Clearing) technique may not be perfect— I haven’t had time to dig into it, so I don’t know— but it’s a fifty-foot neon arrow pointing in the direction things need to go. Since we can’t expect this sort of capability to be added to CSS in the near future, let alone have enough browsers support it in the next few years, scripting our own fixes is the only reasonable solution I can see. For another great big neon arrow of this kind, see Dean Edwards’ IE7.
And yes, I said “tables” back there. If you can avoid using tables for layout, then by all means do, but it isn’t always possible. In such cases, as long as the tables use as little markup as possible, and the markup validates, then I don’t see the problem. Never have, really. My whole objection to tables-for-layout has been, and continues to be, that most table-based designs use way too much markup. Often you see markup-to-content ratios in the vicinity of 3:1. That’s just icky. I much prefer to see the inverse of that ratio, or at least something below 1:1. CSS helps immensely in getting there.
Update: see Shaun’s new new post on the topic, “Absolute Clearance“, for another step in the evolution of his technique. Ever forward!