2012-07-07 93 views
0

我已搜索年齡尋找這個問題的答案!div中的中心div

我正在爲我正在創建的新網站使用12列布局。我有1排4個格:

<div class="colContainer"> 
     <div class="row"> 
      <div class="threecolImg"> 
       <p>Row 1: three</p> 
      </div> 
      <div class="threecolImg"> 
       <p>Row 1: three</p> 
      </div> 
      <div class="threecolImg"> 
       <p>Row 1: three</p> 
      </div> 
      <div class="threecolImg last"> 
       <p>Row 1: three</p> 
      </div> 
     </div> 
    </div> 

我的CSS如下:

.colContainer { 
padding-left: 20px; 
padding-right: 20px; 
} 

.row { 
width: 100%; 
max-width: 1140px; 
min-width: 755px; 
margin: 0 auto; 
overflow: hidden; 
} 

.threecolImg { 
float: left; 
min-height: 1px; 
width: 22.05%; 
} 

,因爲它代表的div都是彼此相鄰(這是很好的!),但不集中(這是不好的!)

可能有人幫我把它們居中?

非常感謝,

保羅

+0

難道顯著你正在使用系統稱爲'三個col',但每行有四個cols?你的意思是將頁面中的外部容器居中? – Utkanos 2012-07-07 23:42:53

+0

4個div在12列網格中是3列寬 – 2012-07-07 23:44:01

回答

1

替換threecol div的所有threecolImg的div。他們將被集中。

<div class="colContainer"> 
    <div class="row"> 
     <div class="threecol"> 
      <p>Row 1: three</p> 
     </div> 
     <div class="threecol"> 
      <p>Row 1: three</p> 
     </div> 
     <div class="threecol"> 
      <p>Row 1: three</p> 
     </div> 
     <div class="threecol last"> 
      <p>Row 1: three</p> 
     </div> 
    </div> 
</div> 

而且從你的CSS刪除:

.threecolImg { 
    float: left; 
    min-height: 1px; 
    width: 22.05%; 
} 

如果你想在threecol的div到的影像風格,更喜歡選擇:

.threecol img { 

} 
+0

感謝您的快速回答HighKick,但這似乎並沒有改變任何東西:( – Paul 2012-07-07 23:43:55

+0

你可以嘗試設置JSFiddle嗎?這裏是一個:http://jsfiddle.net/HighKickX/fdjRk/1 /另外,你使用哪個12列的網格?自制的還是其他的? – 2012-07-07 23:46:11

+0

我使用這個網格:http://cssgrid.net/ 我也上傳了網頁到我的網站: http ://rosesandroyces.co.uk/indexTest.html – Paul 2012-07-07 23:53:35