首页 > 其他 > 详细

盒子模型外边距合并--塌陷问题

时间:2020-10-25 22:53:07      阅读:49      评论:0      收藏:0      [点我收藏+]

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

<!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

盒子模型外边距合并--塌陷问题

原文:https://www.cnblogs.com/runningRain/p/13875085.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!