First, let me make my excuses. As I have said before, I’m self-taught on all this web development stuff, so what I know is usually what I have had a need to use. Which means that sometimes I don’t discover features of the standards that would have been useful to me until pretty late in the game. And that is exactly what happened to me a few weeks ago with the inline-block display property.
Usually when I needed to give an inline element dimension and margins, I would give it a block display and float it to ensure shrink-wrapping of the content. But adding the float would bring its own host of issues to deal with, especially in IE, meaning that doing so was always a headache. So when I discovered the answer to my problems, in the form of the inline-block property—it allows you to give dimension to an inline element as if it was a block element, but it still lays out, and shrinkwraps, as an inline element would—I was ecstatic, for all of the few minutes it took me to discover that Firefox ≤2 doesn’t support inline-block.
So I did some searching, and all I could find on the topic were a few blog posts bemoaning the lack of support, or newsgroup posts asking for help on the subject. Then I came across a potential solution: the proprietary -moz-inline-block property, which was seen by Firefox and ignored by all other browsers. So I tried it, et voilà…it still didn’t work. Firefox seemed to be treating it as a block property; that is, it was forcing a line break afterward. Which didn’t solve my problem at all. After some more searching, I found that I wasn’t the only one having that problem. Back to square one.
More searching. Then I found what I thought was it: the -moz-inline-box property, which is actually supposed to behave like inline-block*, even though -moz-inline-block, which has the same name as the property I want, doesn’t. Huh?
Nevertheless, I tried it, and it worked. But, and by this point you won’t be surprised, in only one case**. The rest of the time, it made my content disappear entirely, or didn’t have the right dimensions, even though I had given those elements fixed widths in my stylesheet. Conclusion: Firefox’s support of inline-block is minimal, buggy at best. It’s best to act as if the property is not available at all.
So what did I do to solve the problem? Pretty much what I had been doing before. I left the element displays as inline-block (for Safari and IE, which support the property) and -moz-inline-block (for Firefox), but added float: left to make it all lay out properly. After all that, I had gotten precisely nowhere. Yeesh.
Despair not, though, gentle reader. Apparently there is a light at the end of the tunnel.
* In most cases. As I found out today.
** My theory on this is that -moz-inline-box will only work on elements with both a fixed height and width. Making it kind of useless in the long run.
Update 2008-07-03 13:04—Firefox 3, as I’m sure you know by know, supports inline-block, so the good news is that you only have to worry about your Firefox 2 users.
Ryan said:
Year old post and inline-block is still not supported in FF. Odd, since FireFox is usually the good guy.
If you’ve got an
<h1>inside the element, it busts the element. To demonstrate drop:<h1>Blah</h1><p></p>
<img />
into your element and watch the breaking.
So even this “hack” has it’s quirks.
we need inline-block! It’s so amazing.
February 24th, 2008 at 9:06 pm
Richa said:
Yeah, it’s really appalling that they don’t support this really very crucial layout feature. Here’s hoping that the support (along with the fix for the stupid scrollbar bleed-through problem) is in Firefox 3.
March 8th, 2008 at 8:24 am
John said:
I found a “hack” at some point that works pretty well. You do a display:table-cell followed by a display:inline-block. Firefox applies the display:table-cell but ignores the display:inline-block, whereas IE applies both, but since inline-block is placed after the table-cell, only the inline-block is functioning in IE. You can still apply width or heighth properties to a table-cell display element, which will be displayed inline.
I agree that firefox does need to fix this inline-block thing, though!!
September 3rd, 2008 at 2:56 pm
Richa said:
Well it’s fixed in Firefox 3, but that doesn’t help us poor schmucks who still have to support Firefox 2 indefinitely.
Thanks for the tip, though!
September 4th, 2008 at 10:15 am
UIDeveloperWeb Blog » Problem: display: inline-block with firefox 2 said:
[...] further details please click here http://richa.avasthi.name/blogs/tepumpkin.old/2007/01/30/talking-shop-firefox-and-inline-block/ Share and [...]
October 19th, 2009 at 6:19 am