IE7 float and clear on the same element

2019-06-11 07:43发布

Here is my code,

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>[your title]</title>
    <style type="text/css">
    .a, .b, .c
    {
        float: left;
    }
    .b
    {
        clear: left;
    }
    </style>
</head>
<body>
<div class="a">1</div>
<div class="b">2</div>
<div class="c">3</div>
</body>
</html>

In IE8, firefox, chrome, safari, opera, the output will be:

1
23

However in IE7:

13
2

I have search for solutions two days already... anyone can help?

Cheers, bGiraffe

3条回答
淡お忘
2楼-- · 2019-06-11 07:52

this should fix it

.a, .b, .c { float: left; }
.b { clear: both; }
查看更多
太酷不给撩
3楼-- · 2019-06-11 08:05

Or you could use the clearfix technique.

http://www.positioniseverything.net/easyclearing.html

查看更多
贪生不怕死
4楼-- · 2019-06-11 08:10
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>[your title]</title>
    <style type="text/css">
    .a, .b, .c
    {
        float: left;
    }
    .b
    {
        clear: left;
    }
    </style>
</head>
<body>
<div class="a">1</div>
<div style="clear: left;"></div>
<div class="b">2</div>
<div class="c">3</div>
</body>

查看更多
登录 后发表回答