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
Great solution! Worked like a charm! 
May 27th, 2010 at 3:23 am
It works!
August 25th, 2010 at 11:41 pm
Thanks. It’ work like a charm.
August 26th, 2010 at 7:51 am
Any reason you can’t float:left & display:block
October 18th, 2010 at 11:11 am
I actually did a double-take when I refreshed and it solved everything! I had a somewhat more complicated hack going on, this makes my life so much easier. Thanks for sharing!
October 26th, 2010 at 11:58 am
Nice one, works like a charm regardless that it’s not compliant css with a W3C scan however we can’t have everything can we?
December 15th, 2010 at 7:14 pm
Thanks so much for posting this, it worked perfectly!
December 17th, 2010 at 5:35 am
Many thanks from Amsterdam!
January 14th, 2011 at 11:44 pm
Thanks from Brazil then. You saved my life.
January 17th, 2011 at 7:35 am
Thanks a lot from St.Pete!
March 14th, 2011 at 1:19 am
This was majorly helpful! Thanks!
April 4th, 2011 at 7:28 am
Thanks so much!
Best Regards
April 7th, 2011 at 3:19 pm
MANY thanks! Works like a charm in IE8 = Tools “incompatibility” mode too
April 17th, 2011 at 11:36 pm
made my day!
April 24th, 2011 at 2:45 am
Thanks. Thanks for the solution. ^_^
April 27th, 2011 at 9:10 am
coooool … thanks a lot
May 2nd, 2011 at 12:44 pm
I cannot tell you have awesome this tip is.
THANK YOU!
I was going mad!
May 23rd, 2011 at 1:41 am
great hack worked just fine!
May 23rd, 2011 at 1:19 pm
Thank You for this simple solution!
It works great, and you saved for me a lot of work!
June 2nd, 2011 at 4:20 pm
Omg, thank you a lot pal !! Greetings from Poland
June 2nd, 2011 at 7:52 pm
*whew* Saved again!
June 14th, 2011 at 3:56 am
Worked great, many thanks!
June 17th, 2011 at 3:22 am
thank you very much!
July 25th, 2011 at 2:17 pm
thx a lot
August 4th, 2011 at 1:09 pm
Many Many thanx =)
August 11th, 2011 at 2:05 am
Thanks …
Very Good Solution
August 12th, 2011 at 10:15 am
Mucho thanks.
August 13th, 2011 at 12:29 am
Great solution for CSS issue. Thanks.
Shane´s last [type] ..MAMP MySQL Won’t Start? – How to Fix the MySQL Server Issue in MAMP
August 17th, 2011 at 6:48 pm
Beautiful.
Thanks for the hack. Works like a charm.
September 4th, 2011 at 11:07 pm
Going to my favorites … Thanks a million!
September 11th, 2011 at 2:43 pm
Thanks! I really needed this.
October 7th, 2011 at 2:41 pm
Unfortunately, this hack breaks the format in FF.
October 16th, 2011 at 10:32 am
Many thanks !!
abderahmane´s last [type] ..ãÇíßÑæÓæÝÊ ÊäÔíÁ ãæÝÚÇð áãÞÇÑäÉ ÏÑÍÉ ÇáÍãÇíÉ Úáì ãÎÊáÝ ÇáãÊÕÝÍÇÊ ÇáãÚÑæÝÉ
October 19th, 2011 at 7:10 am
Thanks. Even in IE9, this basic CSS property is not fixed, but your solution saved me some digging.
November 2nd, 2011 at 6:07 pm
Thank you very much, really helpful
November 4th, 2011 at 5:43 pm
This is brilliant.
Thanks a lot.
November 15th, 2011 at 9:30 am
Thanks dude… awesome work….
December 17th, 2011 at 1:33 am
That’s great, but how “zoom” works?
January 18th, 2012 at 3:34 pm
Awesome hack. Well done!