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>
  • 相关阅读:
    单向循环列表(Java实现)
    单链表的实现(Java实现)
    二分查找法(Java实现)
    六大排序算法(Java实现)
    学习python第十天
    学习python第九天
    MapNode
    AtomicReference
    AtomicStampedReference
    尾递归(TailRecursion)
  • 原文地址:https://www.cnblogs.com/1rookie/p/12008276.html
Copyright © 2011-2022 走看看