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>

在这里插入图片描述

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐