日期:2014-05-17  浏览次数:20640 次

b div在a div中,在b中使用margin-top 为什么a也受到影响?
HTML code

<html>
<head>
    <title>TestDiv</title>
    <style type="text/css">
        *{
            padding:0;
            margin:0;    
        }
        #a{
            width:960px;
            height:700px;
            background-color:red;
            margin: 0 auto;
        }
        #b{
            width:960px;
            height:50px;
            background-color:green;
            margin-top: 10px;
        }
    </style>
</head>

<body>
    <div id="a">
        <div id="b">
        </div>
    </div>
</body>
</html>



------解决方案--------------------
HTML code
<html>
<head>
    <title>TestDiv</title>
    <style type="text/css">
        *{
            padding:0;
            margin:0;    
        }
        #a{
            width:960px;
            height:700px;
            background-color:red;
            margin: 0 auto;
        }
        #b{
            width:960px;
            height:50px;
            background-color:green;
            margin-top: 10px;
            float:left;
            display:inline;
        }
    </style>
</head>

<body>
    <div id="a">
        <div id="b">
        </div>
    </div>
</body>
</html>