2017-07-21 16 views
-2

如果你需要在一個沒有高度的容器內水平和垂直居中放置一個物體,你會如何實現這個目標?如何水平和垂直放置一個沒有設置高度的容器內的對象?

+1

https://www.w3.org/Style/Examples/007/center.en.html –

+1

顯示網格,彎曲,表細胞,...?你有嘗試過什麼嗎? –

+4

[如何垂直居中在一個div內的變量高度的內容?](https://stackoverflow.com/questions/59309/how-to-vertically-center-content-with-variable-height-within-a -div) – hidanielle

回答

0

.centerDiv { 
 
    position: absolute; 
 
    top: 50%; 
 
    left: 50%; 
 
    transform: translate(-50%, -50%); 
 
}
<div class="centerDiv">hello</div>

相關問題