css - ie7 float元素 margin-bottom失效

查看:128
本文介绍了css - ie7 float元素 margin-bottom失效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

ie7-浏览器,父元素float,子元素如果也float,则magin-bottom失效。
为什么呢?父元素float不是触发BFC了吗?
http://output.jsbin.com/liwajir

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .inner{
            float: left;
            width: 100px;
            height: 50px;
            background-color: #8BB5C0;
            margin: 20px;
        }
        .outer{
            float: left;
            background-color: #F9CC9D;
        }
    </style>
</head>
<body>
    <div class="outer">
        <div class="inner"></div>
    </div>
</body>
</html>

解决方案

可能是没有清除浮动的原因吧,模拟不出ie7了,只能这么推测一下。试试看

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .inner{
            float: left;
            width: 100px;
            height: 50px;
            background-color: #8BB5C0;
            margin: 20px;
        }
        .outer{
            float: left;
            background-color: #F9CC9D;
        }
    </style>
</head>
<body>
    <div class="outer">
        <div class="inner"></div>
        <div style="clear: both;"></div>
    </div>
    <div style="clear: both;"></div>
</body>
</html>

这篇关于css - ie7 float元素 margin-bottom失效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆