3

The new display:inline-block attribute seemed like a useful alternative to doing display:block + float:left/right, but the strange spacing/white-space behavior it introduces seems to negate that convenience.(See here and here) On top of that, browser support is spotty and needs fixes, though that will obviously change.

According to this Yahoo UI uses it heavily, but why? Is there a compelling case for using inline-block?

2
  • display: inline-block is not new to CSS3. Commented Mar 3, 2011 at 20:36
  • @BoltClock- oh- assumed it was because of the spotty browser support... Commented Mar 4, 2011 at 4:38

3 Answers 3

6

One useful situation is when you want to have rows of items with variable height. If you were to use floats, then you'd also have to come up with some way to clear all of the second row from the first. Here's an example of that ugly behavior.

But, using the magic of inline-block, here's a version that works. With only two additional CSS rules, it even works in IE6 and 7!

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for illustrating something you can't do with floats- this makes the most sense. But can you explain what the "two additional CSS rules" are all about?
@Yarin IE6/7 don't recognize display:inline-block explicitly, but you get about the same behavior from them by also including *display:inline; zoom:1. The first rule is a hack, the second triggers hasLayout. (Sorry it took so long to get back to you.)
4

I usually use inline-block for inline elements that I want to be able to give height and width to. This is helpful when using sprites (especially for rounded corner buttons using the sliding door method). I don't use it for everything though and I'm more likely to actually use a float when needed than to break a block level element to using inline-block.

2 Comments

And to my recollection inline-block isn't a "standard" implementation. i.e. some browsers can handle it, some can't. At least at my last attempt.
IE7 does ok with it and FF is fine. I haven't tested in Chrome/Safari though (though my guess it will work).
3

Because floats introduce issues in IE in terms of horizontal floats need an explicit width assigned in order to stay on the same horizontal level. With inline-block ( with fixes ) you can avoid assigning explicit widths to the floated items but maintain the blocky inline behaviour that you desire.

You also don't have to clear the items afterwards but I guess that compensates for the inline-block fixes you need to do.

1 Comment

@meder- you always give me something to think about, but this attribute can't only be useful for compensating for an IE float quirk? Love your site btw.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.