2013-10-07 95 views
0

我在wordpress中工作,並且看起來很簡單,讓人有點沮喪。我正在試圖在每個內部構建一組嵌套div的3盒。水平對齊3個嵌套的div

最終產品應該是這樣的:

我可以單獨建立的箱子沒有問題,但是當我試圖用內部嵌套的div來顯示他們,他們垂直對齊,而不是。

這裏是我目前使用的代碼:

#bannercontainer { 
    text-align: center; 
    width: 100%; 
    align: center; 
} 
#bcdiv1 { 
    position: relative; 
    width: 33%; 
} 
#bcdiv2 { 
    position: relative; 
    width: 34%; 
} 
#bcdiv3 { 
    position: relative; 
    float: right; 
    width: 33%; 
} 
#bannerbox { 
    border: 2px solid; 
    border-radius: 10px; 
    background-color: dbdbdb; 
    width: 325px; 
    height: 150px; 
    margin: 5px; 
} 
#bbdivtop { 
border: 2px solid; 
    position: relative; 
    float: top; 
    height: 50px; 
    width: 100%; 
} 
#bbdivleft { 
border: 2px solid; 
position: relative; 
    float: left; 
    width:50px; 
    height: 80px; 
} 
#bbdivright { 
border: 2px solid; 
    position: relative; 
    float: right; 
    height: 80px; 
} 
#bbdivbottom { 
border: 2px solid; 
    position: absolute; 
    bottom: 0; 
    height: 20px; 
    width: 100%; 
    float: bottom; 
} 

和HTML

<div id="bannercontainer"> 

      <div id="bannerbox"> 
       <div id="bbdivtop"> 
       test 
       </div> 
       <div id="bbdivleft"> 
       test 
       </div> 
       <div id="bbdivright"> 
       test 
       </div> 
       <div id="bbdivbottom"> 
       test 
       </div> 
      </div> 
      <div id="bannerbox"> 
       <div id="bbdivtop"> 
       test 
       </div> 
       <div id="bbdivleft"> 
       test 
       </div> 
       <div id="bbdivright"> 
       test 
       </div> 
       <div id="bbdivbottom"> 
       test 
       </div> 
      </div> 
      <div id="bannerbox"> 
       <div id="bbdivtop"> 
       test 
       </div> 
       <div id="bbdivleft"> 
       test 
       </div> 
       <div id="bbdivright"> 
       test 
       </div> 
       <div id="bbdivbottom"> 
       test 
       </div> 
      </div> 
     </div> 
+0

現在正在發生什麼的截圖將幫助:) – veksen

回答

2

添加float:left,改變width to percentagediv with id bannerbox。嘗試:

#bannerbox { 
    border: 2px solid; 
    border-radius: 10px; 
    background-color: dbdbdb; 
    width: 30%; 
    height: 150px; 
    margin: 5px; 
    float:left; 
} 

DEMO FIDDLE

+0

作品!非常感謝! – dftg

0

您有下列2個CSS規則更改代碼...

#bannerbox { 
    border: 2px solid; 
    border-radius: 10px; 
    background-color: dbdbdb; 
    width: 325px; 
    height: 150px; 
    margin: 5px; 
    float: left; 
} 

#bbdivbottom { 
    border: 2px solid; 
    height: 20px; 
    width: 100%; 
    float: right; 
}