jquery - 动态创建的div定位问题

标签 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>

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

最佳答案

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

这里是示例代码:

<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>

关于jquery - 动态创建的div定位问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10371932/

相关文章:

javascript - 具有一个数据绑定(bind)的 Angular 应用程序运行缓慢

javascript - 在 p 标签的宽度内切片文本

c# - 如何将 css 类添加到 ASP.Net 中的更新面板?

c# - 在 Telerik 的 RadScheduler 中,每天顶部的数字都消失了

jQuery,点击事件后中断或重置

javascript - 淡入淡出对页面加载的影响

javascript - 哪个更好 : using $ ("#myVar") directly or saving it to a variable first?

jquery - 向下滚动时如何使div固定在底部?

css - 如何防止底部对齐的 DIV 元素上的文本重叠

css - 使用 css position 定位一个动态加载的搜索结果框