0

我正在以下 heirachy 创建 div

<div class="box">
Content goes here
<div class="footer>Footer</div>
</div>
<div class="box">
Content goes here
<div class="footer>Footer</div>
</div>
<div class="box">
Content goes here
<div class="footer>Footer</div>
</div>

主框“框”是可滚动的。我希望页脚“页脚”保持在父容器的底部,即“框”。我在谷歌上搜索了三天。没有工作。很着急。请帮忙

4

1 回答 1

1

你必须使用绝对位置和底部 0,就像上面说的Sarfraz一样。

这是示例代码:

<html> 
<head> 
<style>
body { width:100%;}
.box { float: left; height: 200px; margin-right: 5%; position: relative; width: 20%;}
.footer {bottom: 0px; position: absolute; width: 100%; text-align: center;}
.box_content{ height: 180px; overflow-y: scroll;}
.clear { clear:both;}
</style> 
</head> 
<body> 
<div class="box">
    <div class="box_content">
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
    </div>
    <div class="footer">Footer</div>
</div>
<div class="box">
    <div class="box_content">
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
    </div>
    <div class="footer">Footer</div>
</div>
<div class="box">
    <div class="box_content">
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
        Content goes here <br />
    </div>
    <div class="footer">Footer</div>
</div>  
<div class="clear"> </div> 
</body> 
</html>
于 2012-04-29T12:14:41.773 回答