html - 底部 :0 not working when overflow-y appear

标签 html css

请看我的jsFiddle http://jsfiddle.net/LY8ze/1/

在我的 div 中有内容和页脚。(2 个部分)页脚必须位于 bottom:0

当没有出现滚动条时。页脚显示正确。但是当滚动条出现时,页脚不会停留在底部。你可以在我的 jsFiddle 中看到它作为第一个数字。

如何仅使用 css 和 html 来解决这个问题?

最佳答案

你正在寻找的是位置固定的,但在你的情况下它会失败,你需要为此使用 jQuery,否则你可以通过使用容器元素来欺骗它,而不是相应地更改标记

Demo

甚至是 better solution (适用于第一种和第二种情况)

1.
<div class="wrap">
<div class="container">
        Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean semper sagittis velit. Cras in mi. Duis porta mauris ut ligula. Proin porta rutrum lacus. Etiam consequat scelerisque quam. Nulla facilisi. Maecenas luctus venenatis nulla. In sit amet dui non mi semper iaculis. Sed molestie tortor at ipsum. Morbi dictum rutrum magna. Sed vitae risus.
        <br />
        <img src="http://i.imgur.com/RKA1Kkk.jpg" style="width:250px;height:150px" />
</div>
    <div class="footer">
        Author : OammieR
    </div>
</div>

CSS

.container {
    height: 250px;
    overflow-y: auto;
    position: relative;
    width: 300px;
    word-wrap: break-word;
    margin:10px;
    padding:5px;
    background-color:#C1C2C3;
}

.wrap {
    background: #c1c2c3;
    width: 330px;

}

.footer {
    color:red;
    padding-left: 15px;
    padding-bottom: 10px;
}

关于html - 底部 :0 not working when overflow-y appear,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17270834/

相关文章:

Python-BeautifulSoup : find td width

javascript - 如何选择第一个td

html - 将 Angular 2 绑定(bind)与 Jade 一起使用的奇怪问题

jquery - 如何使用 .css() 向元素添加多个 CSS 样式

CSS Noob 真的可以在布局和定位方面使用一些熟练的帮助

javascript - 图像映射为圆形区域设置背景图像

javascript - 在没有jquery的情况下将javascript中的JSON输出为列表

javascript - 添加和删​​除表中的行

javascript - 将 div 对齐到 Bootstrap4 卡体的底部

html - 如何在悬停时增加元素的命中框