html - 在一个宽度为 100% 的 div 之后放置宽度为 100% 的页脚

标签 html css

我只是想把我的页脚放在宽度为 100% 的 div 正下方,但如果我使用 position:absolute,它不会是 100% 宽度。

    .box {
    width:100%;
    left:0%;
    height:700px;
    position:absolute;
    margin-top:6%;
    background-image:url();
    background-position-y:90%;
    background-position-x:50%;
}

.footer {
    background-color:#ffffff;
    width:100%;
    height:90px;
    position:absolute;
    bottom:-30%;
    left:0%;
    box-shadow:0px -5px 0px 0px #c72031;
}

HTML:

<div class="box"></div>

<div class="footer"></div>

https://jsfiddle.net/opj984j7/

最佳答案

只需将页脚放在框内并为其指定 bottom: 0; 即可显示,底部没有任何边距。或者要在下方显示,减少页脚高度的 bottom bottom: -90px;:

.box {
  width: 100%;
  left: 0%;
  height: 700px;
  position: absolute;
  margin-top: 6%;
  background: #000;
}
.footer {
  background-color: #ffffff;
  width: 100%;
  height: 90px;
  position: absolute;
  bottom: -90px;
  left: 0%;
  box-shadow: 0px -5px 0px 0px #c72031;
}
<div class="box">
  <div class="footer"></div>
</div>

关于html - 在一个宽度为 100% 的 div 之后放置宽度为 100% 的页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38963143/

相关文章:

javascript - 调整跨域 iframe 高度

html - 如何制作全 Angular Bootstrap 轮播 slider ?

javascript - HTML 无法识别 eventListeners

javascript - jQuery 查找对 xml 标记名使用通配符?

css - 仅使用 css 垂直居中 float div 元素

html - 带文本的主干圆旋转

html - 试图从另一个子文件夹引用 1 个子文件夹

css - 更改 mediawiki 中特定模板的特定标签或按钮的位置和样式?

html - 无法创建适合文本大小的 HTML Div 元素

javascript - 如何使div的背景图像在鼠标悬停时变暗