2012-07-18 78 views
0

我非常渴望不使用表格(不是表格可以工作),但我們有一種情況,用戶需要3列div浮動,一個div有兩個div,其中一個這需要顯示在div的底部。具有一列包含底部Div的CSS相同高度列

也許我需要重新思考整個過程並說服用戶保持簡單。

反正這裏是我的代碼:

<style> 
    #outer-div { 
     overflow: hidden; 
     background-color: grey; 
    } 
    #column-one { 
     padding-bottom: 500em; 
     margin-bottom: -500em; 
     background-color: red; 
     width: 200px; 
     float: left; 
    } 
    #column-two { 
     padding-bottom: 500em; 
     margin-bottom: -500em; 
     background-color: green; 
     width: 200px; 
     float: left; 
    } 
    #column-three { 
     padding-bottom: 500em; 
     margin-bottom: -500em; 
     background-color: blue; 
     width: 200px; 
     float: left; 
    } 
    #column-one-bottom { 
     position: absolute; 
     bottom: 0; 
     background-color: pink; 
    } 
</style> 
<div id="outer-div"> 
    <div id="column-one"> 
     <div id="column-one-top"> 
      Column One Top Data<br/> 
      Column One Top Data<br/> 
      Column One Top Data<br/> 
      Column One Top Data<br/> 
      Column One Top Data<br/> 
     </div> 
     <div id="column-one-bottom"> 
      Column One Bottom Data 
     </div> 
    </div> 
    <div id="column-two"> 
     Column Two Data<br/> 
     Column Two Data<br/> 
     Column Two Data<br/> 
     Column Two Data<br/> 
     Column Two Data<br/> 
     Column Two Data<br/> 
     Column Two Data<br/> 
     Column Two Data<br/> 
     Column Two Data<br/> 
     Column Two Data<br/> 
    </div> 
    <div id="column-three"> 
     Column Three Data<br/> 
     Column Three Data<br/> 
     Column Three Data<br/> 
     Column Three Data<br/> 
    </div> 
    <br style="clear: both;"/> 
</div> 

http://jsfiddle.net/Zre8D/2/

希望有人可以提供幫助。

問題出在#column-one-bottom。我需要這是它的父母的底部,而不是div的中間。

+0

ummm可以提供截圖嗎? – 2012-07-18 12:51:09

+0

我如何提供截圖? – Rob 2012-07-18 12:53:33

+0

http://jsfiddle.net/Zre8D/2/ – Rob 2012-07-18 12:59:25

回答

0
#column-one-bottom { 
    position: absolute; 

嘗試:

#column-one-bottom { 
    position: relative; 
+0

謝謝,試過了,它把分欄中間。需要在父div的底部。 – Rob 2012-07-18 12:55:01

+0

我不跟着你。你可以發佈一個jsfiddle嗎? – 2012-07-19 12:31:15

0

像這樣的事情? http://jsfiddle.net/Zre8D/

HTML:

<div id="outer-div"> 
    <div id="column-one"> 
     <div id="column-one-top"> 
      Column One Top Data<br/> 
      Column One Top Data<br/> 
      Column One Top Data<br/> 
      Column One Top Data<br/> 
      Column One Top Data<br/> 
     </div> 
     <div id="column-one-bottom"> 
      Column One Bottom Data 
     </div> 
    </div> 
    <div id="column-two"> 
     Column Two Data<br/> 
     Column Two Data<br/> 
     Column Two Data<br/> 
     Column Two Data<br/> 
     Column Two Data<br/> 
     Column Two Data<br/> 
     Column Two Data<br/> 
     Column Two Data<br/> 
     Column Two Data<br/> 
     Column Two Data<br/> 
    </div> 
    <div id="column-three"> 
     Column Three Data<br/> 
     Column Three Data<br/> 
     Column Three Data<br/> 
     Column Three Data<br/> 
    </div> 
    <br style="clear: both;"/> 
</div>​ 

CSS:

#outer-div { 
     overflow: hidden; 
     background-color: grey; 
    } 
    #column-one { 
     background-color: red; 
     width: 200px; 
     float: left; 
     position:relative; 
     padding-bottom:200px; 
    } 
    #column-two { 
     background-color: green; 
     width: 200px; 
     float: left; 
    } 
    #column-three { 
     background-color: blue; 
     width: 200px; 
     float: left; 
    } 
    #column-one-bottom { 
     position: absolute; 
     bottom: 0; 
     background-color: pink; 
     overflow:hidden; 
    }​ 
+0

我確實刪除了在em中指定的邊距和填充。對我沒有意義。但是,如果你需要它,你能解釋爲什麼嗎? – AdityaSaxena 2012-07-18 12:56:22

+0

謝謝...但是第二列和第三列不是100%的高度,所以你最終看到灰色(試圖避免看到任何灰色:) – Rob 2012-07-18 12:57:15

0

改變你的風格如下。

<style> 
    #outer-div 
    { 
     height: 100%; 
     background-color: grey; 
    } 
    #column-one 
    { 
     background-color: red; 
     position: absolute; 
     left: 0; 
     width: 200px; 
     height: 100% 
    } 
    #column-two 
    { 
     background-color: green; 
     width: 200px; 
     position: absolute; 
     left: 200; 
     height: 100% 
    } 
    #column-three { 
     background-color: blue; 
     width: 200px; 
     position: absolute; 
     left: 400; 
     height: 100% 
    } 
    #column-one-bottom { 
     position: absolute; 
     bottom: 0; 
     background-color: pink; 
    } 
</style> 
+0

謝謝,但是,如果你在第2列添加幾個或更多
的,它打破了一列的底部。 – Rob 2012-07-18 13:14:32

+0

嘗試編輯答案。 – Narendra 2012-07-18 14:34:44

+0

謝謝。沒有工作:http://jsfiddle.net/Zre8D/13/ – Rob 2012-07-18 15:26:05

0

我設法找到解決方案。已接近解決方案(http://jsfiddle.net/Zre8D/12/):

#outer-div { 
    overflow: hidden; 
    background-color: grey; 
    position: relative; 
} 
#column-one { 
    padding-bottom: 500em; 
    margin-bottom: -500em; 
    background-color: red; 
    width: 200px; 
    float: left; 
} 
#column-two { 
    padding-bottom: 500em; 
    margin-bottom: -500em; 
    background-color: green; 
    width: 200px; 
    float: left; 
} 
#column-three { 
    padding-bottom: 500em; 
    margin-bottom: -500em; 
    background-color: blue; 
    width: 200px; 
    float: left; 
} 
#column-one-bottom { 
    bottom: 0; 
    position: absolute; 
    background-color: pink; 
} 
相關問題