zoukankan      html  css  js  c++  java
  • 居中 子元素无固定 宽高

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>测试模板</title>
        <style>
            *{
                margin: 0;
                padding: 0px;
            }
            /* 第一种
            .parent{
                 400px;height: 200px;background: #797099;
                position: relative;
            }
            .child{
                 200px;height: 100px;background: #eee;
                position: absolute;
                top: 0px;          
                left: 0px;
                right: 0px;
                bottom: 0px;
                margin:auto;            
            } */
    /* 
    第二种
            .parent{
                 400px;height: 200px;background: #797099;
                display:table-cell;
                vertical-align:middle;
                
            }
            .child{
                 200px;
                height: 100px;
                background: #eee;    
                border:2px solid #333;
                margin: 0 auto;            
            } 
    
    */
    
        /* 第三种
        .parent{
                 400px;height: 200px;background: #797099;
                display:table-cell;
                vertical-align:middle;
                text-align: center;
                
            }
            .child{
                 200px;
                height: 100px;
                background: #eee;    
                border:2px solid #333;
                display: inline-block;        
            } */
            /*
            第四种
            .parent{
                 400px;height: 200px;background: #797099;
                display: flex;
                
            }
            .child{
                 200px;
                height: 100px;
                background: #eee;    
                border:2px solid #333;
                margin:auto    
            } */
    
            /*
            第五种
            .parent{
                 400px;height: 200px;background: #797099;
                display: flex;
                justify-content: center;           
                align-items: center;          
            }
            .child{
                 200px;
                height: 100px;
                background: #eee;    
                border:2px solid #333;            
            }
            */
            .parent{
                width:400px;height: 200px;background: #797099;
                position: relative;
            }
            .child{    
                width: 300px; 
                height: 100px;           
                background: #eee;    
                border:2px solid #333;
    
                position: absolute;
                left: 50%;  
                top: 50%;    
                transform:translate(-50%,-50%);
            }
        </style>
    </head>
    <body>
        <div class="parent" >
            <div class="child"></div>
        </div> 
    </body>
    </html>
  • 相关阅读:
    从app加载页面说开去
    NSLog打印各种类型数据的方法
    17个常用代码整理
    成为优秀程序员的10点建议
    iOS常用第三方类库
    iPhone开发如何捕获提交异常日志
    IOS 关于四舍五入的神器NSDecimalNumber
    面向对象与面向过程的一点思考
    程序员,你会为谁卖命?
    关于面向对象的一点思考
  • 原文地址:https://www.cnblogs.com/jinsuo/p/13207846.html
Copyright © 2011-2022 走看看