垂直水平居中
<!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> 相关推荐
  drdrsky    2020-06-16  
   PioneerFan    2020-06-10  
   HSdiana    2020-03-28  
   葉無聞    2020-03-23  
   lyg0    2020-03-07  
   冰蝶    2020-01-10  
   玫瑰小妖    2019-12-31  
   aiolos    2016-04-15  
   loverlucky    2016-03-15  
   WebVincent    2019-07-01  
   云端漂移    2019-07-01  
   renpinghao    2019-06-30  
   kbkiss    2019-06-29  
 