读书人

b div在a div中在b中使用margin-top

发布时间: 2012-02-06 15:52:44 作者: rapoo

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> 

读书人网 >CSS

热点推荐