其他分享
首页 > 其他分享> > 嵌套块元素塌陷处理

嵌套块元素塌陷处理

作者:互联网

塌陷:

  1. 父元素加上overflow:hidden;(常用)
  2. 父元素加上透明border,即border: 1px solid transparent;
  3. 父元素加上上内边距,即padding: 1px
  1.  方法一:
    ​
    
    <style>
            .fa {
                width: 500px;
                height: 500px;
                background-color: crimson;
                margin-top: 50px;
                overflow:hidden;
            }
            .son {
                width: 200px;
                height: 200px;
                background-color: blue;
                margin-top: 200px;
            }
        </style>
    <body>
        <div class="fa">
            <div class="son"></div>
        </div>
    </body>

     

  2. 方法二:
    ​
    ​
    
    <style>
            .fa {
                width: 500px;
                height: 500px;
                background-color: crimson;
                margin-top: 50px;
                border: 1px solid transparent;
            }
            .son {
                width: 200px;
                height: 200px;
                background-color: blue;
                margin-top: 200px;
            }
        </style>
    <body>
        <div class="fa">
            <div class="son"></div>
        </div>
    </body>
    

  3.  方法三:
    ​
    ​
    ​
    
    <style>
            .fa {
                width: 500px;
                height: 500px;
                background-color: crimson;
                margin-top: 50px;
                padding: 1px;
            }
            .son {
                width: 200px;
                height: 200px;
                background-color: blue;
                margin-top: 200px;
            }
        </style>
    <body>
        <div class="fa">
            <div class="son"></div>
        </div>
    </body>

     

标签:塌陷,width,500px,top,元素,height,嵌套,background,200px
来源: https://blog.csdn.net/m0_60679611/article/details/122384823