zoukankan      html  css  js  c++  java
  • 盒子模型外边距合并--塌陷问题

    同时设置子级盒子和父级盒子的外边距,会导致边距设置失效:

    <!DOCTYPE html>
    <html lang="en">
    
    <!-- 解决方案:
    1.可以为父级元素定义边框
    2.可以为父级元素定义内边距
    3.可以为父级元素添加<overflow:hidden></overflow:hidden> -->
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>盒子模型外边距合并--塌陷问题</title>
        <style>
            .father {
                width: 400px;
                height: 400px;
                background-color: purple;
                margin-top: 50px;
                /* 给父元素添加边框 */
                /* border: 10px solid transparant; */
                /* padding: 1px; */
                overflow: hidden;
    
            }
            .son{
                width: 200px;
                height: 200px;
                background-color: pink;
                margin-top: 100px;
            }
        </style>
    </head>
    
    <body>
        <div class="father">
            <div class="son"></div>
        </div>
    </body>
    
    </html>

    解决方式:

    解决方案:
    1.可以为父级元素定义边框
    2.可以为父级元素定义内边距
    3.可以为父级元素添加overflow: hidden
  • 相关阅读:
    python2.7之打飞机(文末附素材链接)
    python画小猪佩奇
    什么叫递归
    DIV居中的几种方法
    什么是控制反转
    上传图片及时预览
    MVC与三层的区别
    From表单提交刷新页面?
    文件上传之form表单篇
    文件上传之伪Ajax篇
  • 原文地址:https://www.cnblogs.com/runningRain/p/13875085.html
Copyright © 2011-2022 走看看