zoukankan      html  css  js  c++  java
  • 最近一个刚刚毕业的朋友说,他面试时候,遇到最频繁的css问题就是垂直居中,这里给出几种垂直居中方式!

    
    
    <!DOCTYPE html>
    <html lang="en">
    <head>
    	<meta charset="UTF-8">
    	<title>Document</title>
    	
    </head>
    <style>
    	html {
        background: #f9f9f9;
        overflow-y: scroll;
    }
    body{
    	font-size: 14px;
    	font-family: "微软雅黑";
    	padding: 0;
    	margin:0 auto;
    }
    
    #child {
    	position:absolute;
    	top:50%;
    	left: 50%;
    	 100px;
    	height:20px;
    	margin:-10px 0px 0px -50px; /* negative half of the height */
        background-color: #ddd;
        text-align: center;
        line-height:20px;
    }
    </style>
    <body>
    <div id="parent">
    		<div id="child">Content here</div>
    </div>
    </body>
    </html>
    

      

    <!DOCTYPE html>
        <head>
            <title>center</title>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
            <style>    
                .root {
                    100%;
                    height:100%;
                    display:table;
                    background-color: rgba(0,0,0,0.5);
                    position: fixed;
                }
                .parent {
                    display:table-cell;
                    vertical-align:middle;
                } 
                .child {
                    50px;
                    height:50px;
                    background:#22B14C;
                    margin:0 auto;
                }            
            </style>
        </head>
        <body>
            <div class="root">
                <div class="parent">
                     <div class="child"></div>
                </div>
            </div>
        </body>
    </html>
    

      

    <!DOCTYPE html>
        <head>
            <title>center</title>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
            <style> 
            body{
                margin:0;
                padding: 0;
    
            }   
                .parent {
                    100%;
                    height:100%;
                    border:1px solid black;
                    position: fixed;
                    background-color: rgba(0,0,0,0.5);
               
                }
                .child {
                    position:absolute;
                    50px;
                    height:50px;
                    top:50%;
                    left:50%;
           
                    -webkit-transform: translate(-50%,-50%);
                        -ms-transform: translate(-50%,-50%);
                       -o-transform: translate(-50%,-50%);
                       transform: translate(-50%,-50%);
                    background:#22B14C;
                }         
            </style>
        </head>
        <body>
            <div class="parent">
                <div class="child">
                     
                </div>
                
            </div>
        </body>
    </html>
    

      

    
    
    
    
  • 相关阅读:
    奇异值分解
    特征值和特征向量
    矩阵
    矢量化
    符号数组
    通用函数
    数据平滑
    多项式拟合
    协方差/相关矩阵/相关系数
    json
  • 原文地址:https://www.cnblogs.com/null11/p/5429634.html
Copyright © 2011-2022 走看看