2012-07-18 163 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; 
} 
相关问题