盒子居中

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .father {
         300px;
        height: 300px;
        display: flex;
    }

    .child {
        margin: auto;
    }

    .father1 {
         300px;
        height: 300px;
        position: relative;
    }

    .child1 {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }

    .father2 {
         300px;
        height: 300px;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .child2 {}
</style>

<body>
    <!-- flexbox布局 -->
    <div class="father">
        <div class="child">
            qweeeeeeeeeee
        </div>
    </div>
    <!-- 子绝父相 -->
    <div class="father1">
        <div class="child1">
            qweeeeeeeeeee
        </div>
    </div>
    <!-- flex布局 -->
    <div class="father2">
        <div class="child2">
            qweeeeeeeeeee
        </div>
    </div>
</body>

</html>
君不见,高堂明镜悲白发,朝如青丝暮成雪
原文地址:https://www.cnblogs.com/lzhflzjx/p/14009635.html