flex 新手学习垂直不居中的原因?

<!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>Document</title>
</head>

<body>
    <style>
        .box {
            display: flex;
            /* justify-content: center; */
            align-items: center;
            /*因为容器没有尺寸所以无法垂直居中*/
            width: 800px;
            height: 800px;
        }
        
        .item {
            width: 100px;
            height: 100px;
            background-color: blue;
        }
    </style>

    <div class="box">
        <span class="item"></span>
    </div>

</body>

</html>

发表评论