I'm confused why IE9 interprets such a basic behavior in a surprising way. In Firefox 4 or Chrome 11 I see that the divs appear side by side as I would expect. In IE9 though, I see the divs appearing one under the other.
<div style='border: black solid 1px'>
<div style='display: inline-block; width: 10em; height: 1em; background-color: red'>
block one
</div>
<div style='display: inline-block; width: 10em; height: 1em; background-color: green'>
block two
</div>
</div>
I'm confident IE9 is standards compliant, so what am I missing?
Any help would be appreciated!
UPDATE: Wow, this is bizarre. I had no DOCTYPE declaration before. The moment I add
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
at the top of the page, IE9 works fine, just like Firefox and Chrome. Any ideas what it was going before?
The only thing I can think of is that IE9 is using Compatibility View (similar to IE7's rendering engine if I'm not wrong) to render your page. If you turn off Compatibility View, you'll see that the boxes stack horizontally as expected.
Only IE8 and newer have full support for
display: inline-block
. IE7 and older apply it to elements that are inline by default (likespan
) and not to any other elements (likeli
ordiv
). As a result, your block elements still display as blocks, not inline blocks.That's easy: before you added your doctype declaration, IE9 was rendering in quirks mode. In quirks mode, IE treats
display: inline-block
just like it did in older versions, as I explain in the above paragraph. By having a doctype declaration, IE9 will render in standards mode, rendering your styles as expected.Try the following it works...
Yes, there are some problems with IE 9 and display: inline-block. It can be avoided with Compatibility lebel as BoltClock explain. My advice is to use float:left instead of display: inline-block
You can find more about Div side by side in one line .
To get it working without DOCTYPE (adding it is not in my control ) i had to use the following css