首页 > 其他 > 详细

用diiv实现多个方块居中嵌套--padding

时间:2019-06-27 20:51:30      阅读:166      评论:0      收藏:0      [点我收藏+]

案例:用diiv嵌套多个正方形,配合盒模型相关知识,使每个div在他的父元素上居中。(每个div中心点对齐)

涉及到margin的各种合并问题。

(触发BFC是更好的解决方案等,为做练习此处只考虑padding)

思路:给减少每个元素的宽高,加给padding。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style type="text/css">
     .first {
         width: 500px;height: 500px;background-color: red;padding: 50px;
     }
     .second {
         width: 400px;height: 400px;background-color: orange;padding: 50px;
     }
     .third {
         width: 300px;height: 300px;background-color: yellow;padding: 50px;
     }
     .forth {
         width: 200px;height: 200px;background-color: green;padding: 50px;
     }
     .fifth {
         width: 100px;height: 100px;background-color: blue;padding: 50px;
     }
     .center {
         width: 0;height: 0;background-color: purple;padding: 50px;
     }
    </style>
</head>
<body>
    <div class="first">
        <div class="second">
            <div class="third">
                <div class="forth">
                    <div class="fifth">
                        <div class="center"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

技术分享图片

 

用diiv实现多个方块居中嵌套--padding

原文:https://www.cnblogs.com/sandraryan/p/11099270.html

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