+ -
当前位置:首页 → 问答吧 → b div在a div中,在b中使用margin-top 为什么a也受到影响?

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

时间:2011-12-08

来源:互联网

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>

作者: cs490864883   发布时间: 2011-12-08

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>



让b浮动就行了~·

作者: MuBeiBei   发布时间: 2011-12-08