首页 > 其他 > 详细

垂直水平居中

时间:2019-12-08 23:29:47      阅读:101      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        /*第一种垂直水平居中*/
        .father{
            width: 300px;
            height: 300px;
            background: red;
            display: table-cell;
            vertical-align: middle;


        }
        .child{
            width: 100px;
            height: 100px;
            margin:0 auto;
        }

        /*第二种垂直水平居中*/
        .father{
            display: flex;
            justify-content: center;
            align-items: center;
            width: 300px;
            height: 300px;
            background: red;
        }
        .child{
            width: 100px;
            height: 100px;
        }


        /*第三种垂直水平居中*/
        .father{
            width: 300px;
            height: 300px;
            background: red;
            position: relative;
        }
        .child{
            width: 100px;
            height: 100px;
            position: absolute;
            left: 0;
            top: 0;
            right: 0;
            bottom: 0;
            margin: auto;
          }

        /*第四种垂直水平居中*/
        .father{
            width: 300px;
            height: 300px;
            background: red;
            position: relative;
        }
        .child{
            width: 100px;
            height: 100px;
            position: absolute;
            left: 50%;
            top: 50%;
            margin-top: -50px;    /* 高度的一半 */
            margin-left: -50px;    /* 宽度的一半 */
        }
    </style>
</head>
<body>

<div class="father">
    <div class="child">123</div>
</div>

</body>
</html>

 

垂直水平居中

原文:https://www.cnblogs.com/1rookie/p/12008276.html

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