css元素真对父元素上下居中

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        body{margin: 0;}
        .box{
            width: 400px;
            height: 400px;
            border:1px solid red;
            display: table-cell;
            vertical-align: middle;
        }
        .item{
            margin:0 auto;
            width:200px;
            background: green;
        }
</style>
</head>
<body>
    <div class="box">
        <div class="item">dddddddddd
            <p>hhhhhhh</p>
        </div>
    </div>
</body>
</html>

 

posted @ 2017-08-24 14:55  大厨的笔记  阅读(216)  评论(0编辑  收藏  举报