动态创建div定位问题

时间:2012-04-29 11:56:53

标签: jquery css position

我在下面的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>

主框“框”是可滚动的。我希望页脚“页脚”保持在父容器i的底部,即“盒子”。我谷歌搜索了三天。没有用。很焦虑。请帮忙

1 个答案:

答案 0 :(得分: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>