zoukankan      html  css  js  c++  java
  • css实现高度或者宽度不固定的div元素垂直左右居中

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <style>
        .demo {
            line-height: 44px;
            margin-bottom: 20px;
            text-align: center;
            background-color: #0078e7;
            color: #fff;
        }
        .flex-equal, .flex-center, .justify {
            display: -webkit-box;
            display: -ms-flexbox;
            display: -webkit-flex;
            display: flex;
        }
    
        .flex-center {
            -webkit-box-pack: center;
            -ms-flex-pack: center;
            -webkit-justify-content: center;
            justify-content: center;
            -webkit-box-align: center;
            -ms-flex-align: center;
            -webkit-align-items: center;
            align-items: center;
        }
        .demo-center .children {
            background: #0078e7;
            color: #fff;
             150px;
            line-height: 5;
            text-align: center;
        }
        .demo-center {
            border: 1px solid #ccc;
            margin: 20px;
            height: 200px;
        }
    
    
        .translate-center {
            position: relative;
        }
        .demo-center .children {
            background: #0078e7;
            color: #fff;
             150px;
            line-height: 5;
            text-align: center;
        }
        .translate-center .children {
            position: absolute;
            top: 50%;
            left: 50%;
            -webkit-transform: translate(-50%, -50%);
            transform: translate(-50%, -50%);
        }
    
    
        .table-equal {
            display: table;
            table-layout: fixed;
             100%;
        }
        .table-equal li {
            display: table-cell;
        }
        .container {
             100%;
            height: 80px;
            background: #C2300B;
            padding-top:10px;
            text-align:center;
        }
        .center{
            display:inline-block;
            border:2px solid #fff;
        }   
        .center{
            _display:inline;
        } /*针对ie6 hack*/  
        .center a{
            float:left;
            border:1px solid #fff;
            padding:5px 10px;
            margin:10px;
            color:#fff;
            text-decoration:none;
        }
        #vc { 
            display:table; 
            background-color:#000; 
            100%; 
            height:200px; 
            overflow:hidden; 
            margin-left:50px;
            _position:relative; 
        }   
        #vci { 
            vertical-align:middle; 
            display:table-cell; 
            text-align:center; 
            _position:absolute; 
            _top:50%; 
            _left:50%; 
        }   
        #content { 
            color:#fff; 
            border:1px solid #fff; 
            display:inline-block; 
            _position:relative; 
            _top:-50%;
            _left:-50%; 
         }  
        </style>
    </head>
    <body>
        <h2>flex居中</h2>
        <div class="flex-center demo-center">
            <div class="children">子元素水平垂直居中</div>
        </div>
        <h2>translate居中</h2>
        <div class="translate-center demo-center">
            <div class="children">子元素水平垂直居中子元素水平垂直居中</div>
        </div>
        <h2>div宽度不固定的div如何设置水平居中</h2>
        <div class="container">   
            <div class="center">
               <a href="#">1</a><a href="#">2</a><a href="#">3</a>   
            </div>
        </div>
        <h2>table居中高度不固定的div垂直居中</h2>
        <div id="vc">
            <div id="vci">
                <div id="content">   
                    我们垂直居中了,我们水平居中了,真的是可以居中的吗,<br />   
                    你信不信我反正是新了<br />   
                    年轻化互联网团队!   
                </div>
            </div>
        </div> 
    </body>
    </html>
    

      

  • 相关阅读:
    Python学习第42天(ftp习题实现day4)
    Python学习第41天(ftp习题实现day3)
    Python学习第40天(ftp习题实现day2)
    Python学习第39天(ftp习题实现day1)
    Python学习第38天(文件处理,os、sys、pickle模块复习)
    Python学习第37天(socketserver继承原理、通讯加密)
    Python学习第36天(socketserver模块导入)
    Python学习第35天(粘包)
    个人读书笔记04—业务用例图
    命令模式
  • 原文地址:https://www.cnblogs.com/dearxinli/p/7986816.html
Copyright © 2011-2022 走看看