美文网首页
2019-08-28

2019-08-28

作者: 深度_1175 | 来源:发表于2019-08-28 16:27 被阅读0次

vertical-align 实现水平垂直居中

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>

    <style>
        * {
            margin: 0;
            padding: 0;
        }

        html,
        body {
            height: 100%;
        }

        .parent {
            height: 100%;
            background-color: #ccc;
            text-align: center
        }

        .parent::after {
            content: "";
            display: inline-block;
            height: 100%;
            vertical-align: middle;
        }

        .son {
            width: 100px;
            height: 100px;
            background-color: red;
            display: inline-block;
            vertical-align: middle
        }
    </style>
</head>

<body>

    <div class="parent">

        <div class="son">
            123
        </div>
    </div>

</body>

</html>

相关文章

网友评论

      本文标题:2019-08-28

      本文链接:https://www.haomeiwen.com/subject/bjrmectx.html