Tag cloud
See my latest projects
About this site
This site is proudly powered by WordPress. If you like what you see, why not subscribe?
Copyright © 2008-2010 Aaron Russell. All rights reserved.
Monday, 27 October 2008
The CSS display property can be the bane of the web designer’s life as support varies from browser to browser, making it all a bit more complicated than it should be. In this article I will show a quick and simple way to get the display:inline-block declaration rendering consistently across all major browsers.
Quirksmode offers a very useful summary of browser support for the display property. As you’d expect, Internet Explorer is the main cause of problems as support for the inline-block value is ‘incomplete’ (read ‘flakey’). Surprisingly, Firefox 2 also causes unexpected problems as the value is not supported at all.
I know most Firefox users actively upgrade and so started using Firefox 3 long ago (which supports inline-block with no issues at all). However, that’s what makes this little problem all the more difficult to spot as chances are you don’t have Firefox 2 lying around for testing any more?
Whilst Firefox 2 doesn’t support inline-block, what it does support is the Mozilla specific -moz-inline-box value – which to you and me and all our end users is exactly the same. So this is easy to fix.
#mydiv .myclass { display: -moz-inline-box; display: inline-block; }
Back to our friend Internet Explorer and we need to add another couple of lines to our CSS to get this working in both IE6 and IE7. By combining a couple of IE version-specific filters with a display:inline declaration after we have made our display:inline-block declaration, Internet Explorer starts behaving itself.
* html .myclass { display:inline; } /* for IE 6 */ * + html .myclass { display:inline; } /* for IE 7 */
Honestly, I have know idea why this works. I’m sure some greater CSS brains than mine out there know exactly what is going on, but for me this doesn’t make sense and is confusing. But… it works, which is good enough.
So when we round all this together we have a snippet of CSS that should look vaguely like this:
.myclass { display: -moz-inline-box; display: inline-block; } * html .myclass { display:inline; } /* for IE 6 */ * + html .myclass { display:inline; } /* for IE 7 */
And there we have it – cross browser support for display:inline-block. Hopefully this tip will save you countless hours of hair-pulling frustration.
“Hopefully this tip will save you countless hours of hair-pulling frustration.”
Too bad that the IE6 implementation doesn’t work for me
. Keeps being block element in IE6 (and I don’t have problems with inline-blocks in IE7?).
[...] Cannot center images gallery for Mopics How to achieve cross-browser support for inline-block :: Aaron Russell ? A wee example would be much appreciated or us slow learners [...]
[...] aaronrussell.co.uk/blog/cross-browser… [...]
I found some other sites, with solutions for this problem, but this one worked best for me. Thanks.
[...] aaronrussell.co.uk/blog/cross-browser… [...]
Thanks! This solution did it!
Even in IE8 they didn’t implent inline-block properly
Here us another way to put it which I think is cleaner:
.myclass {
display: -moz-inline-box;
display: inline-block;
*display:inline;
}
source: http://blog.mozilla.com/webdev/2009/02/20/cross-browser-inline-block/
And one more way )))
.class {
display: -moz-inline-stack;
display: inline-block;
_overflow: hidden;
zoom: 1;
*display: inline;
}
Thanks for this, although I am dropping support for FF2 because I don’t think it’s necessary, as you say, most users of FF will upgrade, and it won’t validate.
Although Oren’s suggestion is cleaner it doesn’t validate, that’s important for me.
So all in all, I think you have the best solution originally.
So, you want cross-browser RGBa support, huh? Well, now you can with my new Compass plugin, rgbapng. Read on to find out more.
As web standards evangelists fall over themselves to point out the hypocrisy of Apple’s Safari-only HTML5 web-standards showcase, I wonder if the liberal use of the term HTML5 means something else?
Today I released a new jQuery plugin called Smart Ass Login Values. It’s a plugin for adding default values to login form fields – like in situations where there can be no text label.
What can only be described as an ee-shit-storm kicked off today, when an ExpressionEngine developer called Alex Gordon released a forked version of the popular EE extension, FF Matrix.
Yesterday Microsoft released to the world a platform preview of IE9. I’m sure you’ve read all about it by now, so what do we all think?
“RT @albertlo: Checking out AirDropper that lets Dropbox users securely requests files from anyone, looking very useful: http://bit.ly/dxKcob”
Posted about 1 hour ago.
This site is proudly powered by WordPress. If you like what you see, why not subscribe?
Copyright © 2008-2010 Aaron Russell. All rights reserved.