<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        /* 方法一 表格 */
        /* .box { 
            display: table;
            width: 200px;
            height: 200px;
            background: yellow;
        }
        .box>div{
            background: red;
            display: table-cell;
            vertical-align: middle;
            text-align: center;
        } */

        /* 方法二  transform */
        /* .box { 
            position: relative;
            width: 200px;
            height: 200px;
            background: yellow;
        }
        .box>div{
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
            background: red;
        } */

        /* 方法三 flex */
        .box {
            display: flex;
            width: 200px;
            height: 200px;
            background: yellow;
            align-items: center;
            justify-content: center;
        }
        .box>div{
            background: red;
        }
    </style>
</head>
<body>
    <div class="box">
        <div>hello world-1</div>
    </div>
</body>
</html>
posted on 2019-02-28 11:15  佑之以航  阅读(222)  评论(0编辑  收藏  举报