zoukankan      html  css  js  c++  java
  • 垂直水平居中的几种方式,其他方式还有很多,不再列举

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            /*第一种垂直水平居中*/
            .father{
                 300px;
                height: 300px;
                background: red;
                display: table-cell;
                vertical-align: middle;
    
    
            }
            .child{
                 100px;
                height: 100px;
                margin:0 auto;
            }
    
            /*第二种垂直水平居中*/
            .father{
                display: flex;
                justify-content: center;
                align-items: center;
                 300px;
                height: 300px;
                background: red;
            }
            .child{
                 100px;
                height: 100px;
            }
    
    
            /*第三种垂直水平居中*/
            .father{
                 300px;
                height: 300px;
                background: red;
                position: relative;
            }
            .child{
                 100px;
                height: 100px;
                position: absolute;
                left: 0;
                top: 0;
                right: 0;
                bottom: 0;
                margin: auto;
              }
    
            /*第四种垂直水平居中*/
            .father{
                 300px;
                height: 300px;
                background: red;
                position: relative;
            }
            .child{
                 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>
  • 相关阅读:
    Ajax入门
    多线程入门(五)
    多线程入门(四)
    多线程入门(三)
    多线程入门(二)
    多线程入门(一)
    git使用简介
    Windows远程登录到VirtualBox安装的Ubuntu11.10
    阿里面试2(转)
    百度java开发面试题
  • 原文地址:https://www.cnblogs.com/1rookie/p/12008276.html
Copyright © 2011-2022 走看看