首页 > Web开发 > 详细

css垂直居中的四种方法

时间:2017-09-28 18:34:52      阅读:290      评论:0      收藏:0      [点我收藏+]

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>垂直居中</title>
    <style>
    .parent{width: 400px;height: 400px;border:1px solid grey;display: }
    .children{width: 200px;height: 200px;background-color: #ccc;}
    /*table-cell*/
    .parent{display: table-cell;text-align: center;vertical-align: middle;}
    .children{display: inline-block;}
    /*flex*/
    .parent{display: flex;justify-content: center;align-items: center;}
    /*position transform*/
    .parent{position: relative;}
    .children{position: absolute;top:50%;left: 50%;transform:translate(-50%,-50%);}
    /*position margin 不推荐使用,使用必须设置宽高*/
    .parent{position: relative;}
    .children{position: absolute;top:0;left: 0;bottom: 0;right: 0;margin: auto;}
</style>
</head>
<body>
    <div class="parent"  >
        <div class="children">
        </div>
    </div>
</body>
</html>

css垂直居中的四种方法

原文:http://www.cnblogs.com/XUseven/p/7607940.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!