html - 将栏粘贴到容器的页脚

标签 html css

在此Fiddle ,即使用户滚动容器,我也试图将栏始终保持在左下角。目前,如果我滚动容器,栏会移动,而不是总是粘在页脚上。

虽然这似乎是默认行为,但我并没有意识到这一点。所以,任何解释都会很有帮助。 (我的预期是它会粘在容器底部)。

需要考虑的事项:

  • 当水平调整大小时,该条应该超过容器的水平滚动条。 (当前正在发生)
  • 栏应始终位于容器的底部。 (没有发生)

.parent {
  width: 60%;
  height: 300px;
  position: absolute;
  background-color: tomato;
  overflow: auto;
}
.content {
  height: 18000px;
  width: 300px;
  background-color: firebrick;
}
.bar {
  position: absolute;
  bottom: 0;
  left: 0;
  line-height: 20px;
  text-align: center;
  width: 50px;
  height: 20px;
  background-color: beige;
}
<div class="parent">
  <div class="content"></div>
  <div class="bar">BAR</div>
</div>

最佳答案

试试这个 CSS

.grand-parent{
  position: relative;

}
.parent {
  width: 60%;
  height: 300px;
  overflow: auto;
  background-color: tomato; 
}
.content {
  height: 18000px;
  width: 300px;
  background-color: firebrick;
}
.bar {
  position: absolute;
  bottom: 0;
  left: 0;
  line-height: 20px;
  text-align: center;
  width: 50px;
  height: 20px;
  background-color: beige;
}

HTML

<div class="grand-parent">
  <div class="parent">
    <div class="content"></div>
  </div>
  <div class="bar">BAR</div>
</div>

关于html - 将栏粘贴到容器的页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31308946/

相关文章:

html - CSS 内容重叠

javascript - 提交表单后关闭书签

javascript - 最大高度 div 和 div 中以及 div 中的段落

android - 在手机浏览器上单击图标时显示边框

html - 表高度不工作

html - getContext ('2d' ) 在 Safari 10 中返回 null

javascript - 如何使用 3D 变换获取元素的未变换位置/大小?

javascript - Html 5 Canvas 矩形删除和绘制后

html - 关于在绝对定位的文本区域上使用左/上/右/下

使用 include() 时 php 无法使用 bootstrap