flex布局 水平垂直居中 亲测有效

flex布局
任何一个容器都可以指定为Flex布局。

.box{
display: flex;
}
行内元素也可以使用Flex布局。

.box{
display: inline-flex;
}
Webkit内核的浏览器,必须加上-webkit前缀。

.box{
display: -webkit-flex; /* Safari */
display: flex;
}
注意,设为Flex布局以后,子元素的float、clear和vertical-align属性将失效。
详细请参考 https://www.runoob.com/w3cnote/flex-grammar.html

<html>
<head></head>
<style>
    * {
        margin: 0px;
        padding: 0px
    }

    body {
        display: flex;
        align-items: center; /*定义body的元素垂直居中*/
        justify-content: center; /*定义body的里的元素水平居中*/
    }

    body div {
        display: flex;
        align-items: center; /*定义body的元素垂直居中*/
        justify-content: center; /*定义body的里的元素水平居中*/

    }
</style>
<body>
<div style="width: 800px;height: 800px;background-color: whitesmoke;margin: auto;">
    <div style="width:700px;height: 700px;background-color: honeydew;margin: auto;text-align: center;">
        <div style="width:600px;height: 600px;background-color: #c0c4cd;margin: auto;text-align: center;">
            <div style="width:500px;height: 500px;background-color: coral;margin: auto;text-align: center;">
                <div style="width:400px;height: 400px;background-color: cadetblue;margin: auto;text-align: center;">
                    <div style="width:300px;height: 300px;background-color: black;margin: auto;text-align: center;">
                        <div style="width:200px;height: 200px;background-color: blue;margin: auto;text-align: center;">
                            <div style="width:100px;height: 100px;background-color: red;margin: auto;text-align: center;">
                                <span></span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>

在这里插入图片描述

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值