2015-08-25 76 views
0

我在右側有一個側邊欄,我想爲左側的Tumblr帖子創建兩個居中的列。我能做什麼?在#wrapper爲什麼我不能居中這個div?

 #wrapper /*for two columns*/ { 
      display: inline-block; 
      margin: 15px 15px 15px 30px; 
     } 
     #wrapper .posts { 
      width: 400px; 
      margin: 0 15px 15px 0px; 
      padding: 10px; 
     } 
     #sidebar /*including some other stuff, obviously*/ { 
      display: table; 
      width: 250px; 
      height: 100%; 
      position: fixed; 
      top: 0px; 
      right: 0px; 
     } 
+2

請包括html – kheld

+0

'display:table;身高:100%;'這不起作用。您無法控制具有'display:table;'的元素的高度。 – connexo

+0

@connexo然而,它確實有效!問題不在於身高,而在於圍繞#wrapper! – danya

回答

0

你的水平margin S的關係被設定爲auto。這是關鍵。父母(可能是body)可能還需要設置text-align: center

1

爲了使HTML元素居中對齊:

對於塊元素如div, p, ..etc.,這些應該有widthmax-width設置爲某個值,應該有margin-left: auto & margin-right:auto

對於內聯元素如span, em, ..etc.,我們可以通過給其父元素提供text-align:center來對齊。