So I am doing like so
<div style='width: 200px; border: 1px solid black;'>
<div style='display: inline-block; width: 70px; border: 1px solid green;'>
asdfasdf<br />asdf
</div>
<div style='display: inline-block; width: 70px; border: 1px solid green;'>
asdfasdf<br />were
</div>
</div>
Now in firefox and chrome it displays just fine but in internet explorer 8 it does not. They have layout so that isn't the problem, and the widths are small enough so it fits on one line.
If I use span's instead it does work, however I would really like to konw why div's dont' work in IE
The old versions of IE don't understand the
inline-block
for block-level elements.The reason why
inline-block
works for inline elements is because they did it so it triggershasLayout
. And the has layout for inline elements works exactly like aninline-block
.So, to make
inline-block
work with block-level elements, make them inline and somehow trigger thehasLayout
, like, usingzoom: 1
.So, for you code, there are two ways: change
div
s tospan
s, or add inline hacks (or move the code to external stylesheets and use conditional comments). The version with inline hacks would look like this:Changing the doc type worked for IE
IE < 8 cannot switch elements that are
block
by default toinline-block
elements. No matter how hard you try, they will always remainblock
unless you usefloat
IIRC.In your example it seems that you do not need to use a
<div>
. If this is the case, why not use a<span>
or an element that isinline
by default. Otherwise,floating
is the answer.Try this
display: inline-block; *zoom: 1; *display: inline;
you can add inline-block for other browser but for IE you can add style with *. it only works in ie