方法1:table-cell
html結(jié)構(gòu):
        垂直居中
css:
.box1{
    display: table-cell;
    vertical-align: middle;
 text-align: center;        
}
方法2:display:flex
.box2{
    display: flex;
    justify-content:center;
    align-items:Center;
}
方法3:絕對定位和負(fù)邊距
復(fù)制代碼
.box3{position:relative;}
 .box3 span{
            position: absolute;
 width:100px;
 height: 50px;
            top:50%;
left:50%;
 margin-left:-50px;
            margin-top:-25px;
            text-align: center;
        }
方法4:絕對定位
 .box4 span{
  width: 50%; 
  height: 50%; 
  background: #000;
  overflow: auto; 
  margin: auto; 
  position: absolute; 
  top: 0; left: 0; bottom: 0; right: 0; 
}
這種方法跟上面的有些類似,但是這里是通過margin:auto和top,left,right,bottom都設(shè)置為0實(shí)現(xiàn)居中,很神奇吧。不過這里得確定內(nèi)部元素的高度,可以用百分比,比較適合移動端。
方法5:translate
	
.box6 span{
            position: absolute;
            top:50%;
            left:50%;
            width:100%;
            transform:translate(-50%,-50%);
            text-align: center;
        }
這實(shí)際上是方法3的變形,移位是通過translate來實(shí)現(xiàn)的。
 方法6:display:inline-block
	
.box7{
  text-align:center;
  font-size:0;
}
.box7 span{
  vertical-align:middle;
  display:inline-block;
  font-size:16px;
}
.box7:after{
  content:';
  width:0;
  height:100%;
  display:inline-block;
  vertical-align:middle;
}
這種方法確實(shí)巧妙...通過:after來占位。
 方法7:display:flex和margin:auto 
 .box8{
    display: flex;
    text-align: center;
}
.box8 span{margin: auto;}
方法8:display:-webkit-box
.box9{
    display: -webkit-box;
    -webkit-box-pack:center;
    -webkit-box-align:center;
    -webkit-box-orient: vertical;
    text-align: center
}
 css3博大精深,可以實(shí)現(xiàn)很多創(chuàng)造性的效果,需要好好研究下。
 方法9:display:-webkit-box
這種方法,在 content 元素外插入一個(gè) div。設(shè)置此 div height:50%; margin-bottom:-contentheight;。
content 清除浮動,并顯示在中間。
  
 Content here 
  
.floater {
    float:left; 
    height:50%; 
    margin-bottom:-120px;
}
.content {
    clear:both; 
    height:240px; 
    position:relative;
}
優(yōu)點(diǎn): 
適用于所有瀏覽器 
沒有足夠空間時(shí)(例如:窗口縮小) content 不會被截?cái)?,滾動條出現(xiàn)
缺點(diǎn): 
唯一我能想到的就是需要額外的空元素了(也沒那么糟,又是另外一個(gè)話題)