views:

977

answers:

4

IE 7 and IE 8 do not render 2 consequent divs with float:left on the same line if there is a table in one of the DIVs which is 100% width + non-zero margin:

<html>
<head>
<title>IE float left bug</title>
<style type="text/css">
.inttable
{
    width: 100%;
    margin: 9px;
}
.multicolumn 
{
    margin: 0px;
    border: 0px;
    padding: 0px;
    width:100%;
}
.column 
{
    margin: 0px;
    border: 0px;
    padding: 0px;
    float:left;
    display: inline;
}
</style>
</head>
<body>
<div class="multicolumn">
    <div class="column" style="width:50%;">
     <table class="inttable">
      <tr>
       <td>table1</td>
      </tr>
     </table>
    </div>
    <div class="column" style="width:50%;">
        column 2
    </div>
</div>
</body>
</html>

There is no such problem in FireFox, Opera, Chrome and Safari.

Does anyone know workaround for this IE bug?

A: 

interesting, does changing display: inline; to display: inline-block; do anything?

edit: doesnt do anything, but removing margin:9px from table fixes it

also, adding colored borders to everything makes for easy debugging

mkoryak
Nope. Did not help in IE 7.
Artem
Yes, removing margin fixes it, but I need margin in my case.
Artem
A: 

Changing margin: 9px; to padding: 9px; solves the problem in my case.

Artem
A: 

The bug seems to be a 1px shift introduced by IE's terrible rendering engine.

The margin on the table inevitably pushes the floated div outward in IE, so the simplest working solution I've found is to add a negative left margin to the second column equal to your table's margin + 1 px. So in this case it'd be margin-left:-19px;

That's a bizarre and frustrating bug. Hope this solution works for you.

Gabriel Hurley
+1  A: 

As scunliffe mentioned in his comment making this html transitional or strict xhtml solves the issue.

Artem