views:

214

answers:

2

Unfortunately I have to support IE7 (and preferably IE6) In IE8, Safari, Firefox, Chrome, I get a perfectly good layout ujsing an outer div to enlose two boxes.

------------------------------------
|                                  |
|  --------------     -----------  |
|  |            |     |         |  |
|  |     A      |     |    B    |  |
|  |            |     |         |  |
|  --------------     -----------  |
|                                  |
------------------------------------

I'm using inline-block to style A and B. A is floated left, B right. Both boxes have internal divs and other elements.

However, when I use IE6 and IE7 I get this monstrosity.

------------------------------------
|                                  |
|  --------------                  |
|  |            |                  |
|  |     A      |                  |
|  |            |                  |
|  --------------                  |
|                     -----------  |
|                     |         |  |
|                     |    B    |  |
|                     |         |  |
|                     -----------  |
|                                  |
------------------------------------

Any definitive answers to what is going on and how to solve it?

A: 

In IE 6 and 7 inline-block works only on elements that have a natural display: inline. Are your boxes <div>s? If yes, it should work.. Do you have a test case? (See quirksmode.org for more info!)

IE block level element inline-block hack: this may be useful for you

Andreas Bonini
Using `inline-block` cross-browser is easier than that: `your selector { display: -moz-inline-box; /* Firefox < 3, will be quirky in some edge cases... */ display: inline-block; *display: inline; *zoom: 1; /* Star hack targets IE < 8; zoom triggers hasLayout with no other side-effects */`
eyelidlessness
+3  A: 

Firstly, put a DOCTYPE at the top of your document. This forces IE into standards compliant rather than quirks mode (both euphemisms). For example:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"&gt;

Secondly, if you want IE6 compatibility use floats (Andrew is quite correct in stating that display: inline-block only works in IE7 on elements with natural display: inline and <div> has natural display: block). This should work:

<div id="outer">
  <div id="left"></div>
  <div id="right"><>/div>
</div>

with:

#outer { overflow: hidden; }
#left { float: left; }
#right { float: right; }

as long as the widths of left and right are less than the width of outer including padding, borders and margins. If not, right will drop down to the next line.

cletus
Note: not just **a** doctype, but a **strict** doctype. See the table at bottom of this site for a list of all doctypes and the browser behaviour (you at least don't want quirks mode): http://hsivonen.iki.fi/doctype/
BalusC
Vote up.. just after using floats add <div style="clear:both;"></div>
c0mrade
You don't need the "clear: both" bit if you change the overflow property on the container.
cletus