127

Can someone please help me get my head around this bug? With Firefox its working fine but with Internet Explorer 7 its not. It seems not to understand the display: inline-block;.

html:

<div class="frame-header">
    <h2>...</h2>
</div>

css:

.frame-header {
    height:25px;
    display:inline-block;   
}
1
  • 1
    What exactly to you to achieve? What effect?
    – Iladarsda
    Jul 1, 2011 at 7:39
302

The IE7 display: inline-block; hack is as follows:

display: inline-block;
*display: inline;
zoom: 1;

By default, IE7 only supports inline-block on naturally inline elements (Quirksmode Compatibility Table), so you only need this hack for other elements.

zoom: 1 is there to trigger hasLayout behaviour, and we use the star property hack for setting the display to inline only in IE7 and lower (newer browsers won't apply that). hasLayout and inline together will basically trigger inline-block behaviour in IE7, so we are happy.

This CSS will not validate, and can make your stylesheet messed up anyways, so using an IE7-only stylesheet through conditional comments could be a good idea.

<!–-[if IE 7]>
<link rel="stylesheet" href="ie7.css" type="text/css" />
<![endif]–->
7
  • 40
    I prefer *zoom:1; to triger hasLayout. So it's more clearly that the *zoom and *display go together
    – yunzen
    Nov 14, 2012 at 12:25
  • 4
    @RoshanWijesena w3schools has nothing to do with w3c and neither are authorities on ie7
    – Musa
    Apr 14, 2013 at 0:51
  • 1
    @RoshanWijesena w3schools is not a good resource and is not official at all. Do not depend on it. The fact that they mention or do not mention something does not really mean anything.
    – kapa
    Apr 16, 2013 at 7:04
  • 1
    thanks Guys! so what should i used as a official documentation just wondering! Apr 16, 2013 at 8:22
  • 2
    @RoshanWijesena You can find the offical standard specifications on w3.org, the official page of W3C. developer.mozilla.org is a great resource that you can use instead of w3schools as a reference.
    – kapa
    Apr 16, 2013 at 8:59
8

Update

As nobody uses IE6 and 7 anymore I will present a different solution:
You don't need a hack anymore, because IE8 supports it by itself

For those who must support those stone age browsers before IE8 (It's not that the IE8 is that old, too cough):
For the account of IE version control, use some Conditional Class in <html>tag like Paul Irish states in his article

<!--[if IE 7]><html class="no-js lt-ie9 lt-ie8"><![endif]-->
<!--[if IE 8]><html class="no-js lt-ie9"><![endif]-->
<!--[if gt IE 8]><!--><html class="no-js"><!--<![endif]-->

By this you will have different classes in html-tag for different IE Browsers

The CSS you need is as follows

.inline-block {
    display: inline-block;
}
.lt-ie8 .inline-block {
    display: inline;
    zoom: 1;
}

This will validate and you don't need an extra CSS file


Old answer

.frame-header
{
    background:url(images/tab-green.png) repeat-x left top;
    height:25px;
    display:-moz-inline-box;    /* FF2 */
    display:inline-block;   /* will also trigger hasLayout for IE6+7*/
}
/* Hack for IE6 */
* html .frame-header {
    display: inline; /* Elements with hasLayout and display:inline behave like inline-block */
}
/* Hack for IE7 */
* + html .frame-header {
    display: inline; /* Elements with hasLayout and display:inline behave like inline-block */
}
2
  • The CSS you show above makes sense but how exactly would that work into the HTML? Thanks.
    – StephenESC
    Sep 13, 2014 at 3:51
  • @StephenESC two ways. Add the class inline-block to the frame-header element. Or change inline-block by frame-header in the CSS selectors.
    – yunzen
    Sep 13, 2014 at 4:33
1

IE7 does not support 'inline-block' properly, more info here: LINK
Use can use: 'inline' instead.

What exactly are you trying to achieve? Make us an example and put here: http://jsfiddle.net/

0
0

use inline, it works with this kind of selectors for list items:

ul li {}

or to be specific:

ul[className or name of ID] li[className or name of ID] {}
1
  • 2
    inline is not the same as inline-block. For example, the height: 25px; in the example will not take effect when the element is inline. Also, the question says nothing about lists.
    – kapa
    Apr 25, 2013 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.