用多个div实现多个方块居中嵌套

今天教大家用多个div实现多个方块居中嵌套的实例。本例用到了flex布局里的justify-content属性和align-items属性,此方法较为方便快捷,不用多次去设置div的内外边距,其次还涉及到border边框的一些应用。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>花样边框</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        div{
            display: flex;
            justify-content: center;
            align-items: center;
        }
        .one{
            width: 450px;
            height: 450px;
            border: 3px dotted black;
            margin: 20px auto;
        }
        .two{
            width: 400px;
            height: 400px;
            border: 3px solid gray;
        }
        .three{
            width: 350px;
            height: 350px;
            background-color: rgb(150, 48, 48);
        }
        .four{
            width: 280px;
            height: 280px;
            border: 2px dotted white;
        }
        .five{
            width: 250px;
            height: 250px;
            border: 2px dotted white;
        }
        .six{
            width: 200px;
            height: 200px;
            border: 2px solid black;
        }
    </style>
</head>
<body>
    <div class="one">
        <div class="two">
            <div class="three">
                <div class="four">
                    <div class="five">
                        <div class="six"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

最后效果:

 

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值