垂直居中容器

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .parent{
            width: 400px;
            height: 400px;
            border:1px solid gray;
            position: relative;
        }
        .child{
            width: 100px;
            height: 100px;
            top:0;
            left:0;
            right:0;
            bottom:0;
            margin:auto;
            background: pink;
            position: absolute;
        }
    </style>
</head>
<body>
    <div class="parent">
        <div class="child"></div>
    </div>
</body>
</html>

推荐阅读更多精彩内容