1.第一个子级的margin top 会传递给父级

来源:互联网 发布:二维数组怎么赋值 编辑:程序博客网 时间:2024/04/29 07:11

1.第一个子级的margin top 会传递给父级

   解决办法 如下:
     1.给父级添加border;
        2.父级使用overflow:hidden;
           3.不要使用margin-top 用父级padding-top 温馨提示:注意盒子的空间

<!-- <!DOCTYPE html>

<html>
<head>
    <meta charset="UTF-8">
    <title>asd</title>
    <link rel="stylesheet" href="css/reset.css">
    <style type="text/css">
    #a{
        margin: 0 auto;
        width: 500px;
        height: 500px;
        background: blue;
    /*    margin-top:20px; */
    }
    #b{
        width: 300px;
        height: 300px;
        background: red;
    /*    margin-top:20px; */
    }
    #c{
        width: 100px;
        height: 100px;
        background: yellow;
        /*margin-top:20px; */
        margin-left: 20px;
    }
    </style>
</head>
<body>
<div id="a">
    <div id="b">
        <div id="c">
            
        </div>
    </div>
</div>
</body>

</html> -->


1 0
原创粉丝点击