CSS: inline-block IE7 Hack
Thursday, October 22nd, 2009I was demoing a recent web design to a client when I noticed that the menu items were not displaying correctly. The client uses ie7. While Firefox is my primary browser, I usually test my design in IE and Safari (and tweak if necessary). I didn’t this time because I did not think there was a difference for the CSS styles that I was using. I was wrong.
I usually use li elements for menu items:
<ul> <li><a>Home</a></li> <li><a>About</a></li> <li><a>Contact</a></li> </ul> |
To create horizontal menu items, I change the display attribute to inline in my CSS file.
li { display:inline; } |
For this particular design, I added a vertical divider (image) between each menu item. In order to do this, I used the inline-block attribute.
#menu li { display:inline-block; margin:0; list-style:none; width:122px; height:45px; background-image:url(images/menu_divider.jpg); background-repeat:no-repeat; background-position:top left; text-align:center; padding:0; } |
This looks fine in Firefox and Safari, but IE7 (and IE6) only supports inline-block on elements with natural display: inline. See CSS Display declaration.
I found a hack. Adding zoom: 1 and *display: inline will make IE7 display the li’s as inline-block.
#menu li { display:inline-block; margin:0; list-style:none; width:122px; height:45px; background-image:url(images/menu_divider.jpg); background-repeat:no-repeat; background-position:top left; text-align:center; zoom: 1; *display:inline; padding:0; } |
Next time, I will remember to test my designs in the major browsers before it is shown to the client.



November 7th, 2009 at 2:00 pm
That’s a great resolution for another ie f***-up.
Many thanks!
Nath
December 7th, 2009 at 6:46 am
Cross-Browser Inline-Block::
http://ledomoon.blogspot.com/2009/12/cross-browser-inline-block.html
waleed ´s last blog ..Cross-Browser Inline-Block =-.
December 21st, 2009 at 5:37 pm
Thank you, thank you, thank you!!!!
January 5th, 2010 at 11:06 am
Yap, thanks a lot from Latvia too
May 27th, 2010 at 3:23 am
It works!