2017-01-16 142 views

回答

0

這是最好的方式,以內容爲中心垂直

.vert-center { 
    margin-top: 50%; 
    translate: transform-y(-50%); 
} 
0
.wrap { position:relative; } 
.center { 
width:100%; 
height:100%; 
top:0; 
right:0; 
left:0; 
bottom:0; 
display:flex; 
position:absolute; 
text-align:center; 
align-items:center; 
justify-content:center; 
} 



<div class="wrap"> 

    <div class="center"> 

     <div> 

      <h1>Title</h1> 

      <span>span</span> 

     </div> 

    </div> 

</div> 
0
.title 
{ 
    border: 1px solid green; 
    position: relative; 
    top:50%; 
    transform: translateY(-50%); 
}