父子DIV发生margin重叠

来源:互联网 发布:mac直播音效软件下载 编辑:程序博客网 时间:2024/06/06 02:56
原文链接:http://blog.sina.com.cn/s/blog_40824a5d0102vymi.html

第一步:
设置两个父子div,均不设margin值。
《style type="text/css"》
    #container{
        height: 500px;
        background: blue;
    }
    #test{
        height: 100px;
        width: 100px;
        background: yellow;
    }
《/style》
-------------------------
《body》
    《div id="container"》
        《div id="test"》《/div》
    《/div》
《/body》

效果如下:
父子DIV发生margin重叠
第二步:
只把父div的margin四边都设为100px。
#container{
        height: 500px;
        background: blue;
        margin:100px;
    }
效果如下:
父子DIV发生margin重叠
这个比较好理解。


第三步:
只把父div和子div的margin四边都设为100px。
#container{
        height: 500px;
        background: blue;
        margin:100px;
    }
#test{
        height: 100px;
        width: 100px;
        background: yellow;
        margin:100px;
    }
效果如下:
父子DIV发生margin重叠


第四步:
只把子div的margin四边都设为100px。
#test{
        height: 100px;
        width: 100px;
        background: yellow;
        margin:100px;
    }
效果如下:
父子DIV发生margin重叠
原创粉丝点击