CSS block elements on a line

Dan Monego picture Dan Monego · Nov 21, 2008 · Viewed 29.1k times · Source

What's the most common way to deal with a series of block elements that need to be on a line (if javascript needs to be able to modify their widths, for example)? What are the pros and cons to applying float:left to each of them vs. using positioning to place them?

Answer

Gabe picture Gabe · Nov 21, 2008

Well, if you're not too concerned with older browsers (I'm looking at you, IE6) the best way here is to go with

display:inline-block;

Basically, it creates a box-model element without clearing before or after it, so it remains in the line. Every modern browser interprets it well.