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>
  • 相关阅读:
    CSS文本部分之字体样式[1]
    CSS基础之简单介绍
    [09]HTML基础之全局属性
    [08]HTML基础之视频标签
    [07]HTML基础之图片标签
    [06]HTML基础之表单标签
    [05]HTML基础之表格标签
    sonarqube启动报错
    rhel6下kvm克隆后的操作登录新克隆的虚拟机重新配置网络
    解决KVM 宿主机redhat6系统上shutdown关不了虚拟机的问题
  • 原文地址:https://www.cnblogs.com/jinsuo/p/13207846.html
Copyright © 2011-2022 走看看