html - 拖车 div 内的粘性页脚

标签 html css

我正在尝试制作一个始终位于底部的粘性页脚。但我的页脚不是第一个 div 的直接子元素,它是第二个子元素。像这样https://jsfiddle.net/bduswush/

<div id="outer-wrap">
    <div id="inner-wrap">
        <div class="head">This is head</div>
        <div class="content">This is body</div>
        <div class="footer">This is footer</div>
    </div>
</div>

但问题就在这里——它没有占据设备屏幕的整个高度,内容 div 被页脚重叠。我想自动离开页脚高度。有什么解决办法吗??提前致谢。

最佳答案

您必须为 htmlbody 标签设置 heightwidth

html,body{
  height: 100%;
  width: 100%;
  border: 0;
}

html,body{
  height: 100%;
  width: 100%;
  border: 0;
}
#outer-wrap {
	height: 100%;
  background: #ccc;
}
#inner-wrap {
	min-height: 100%;
	position: relative;
  background: #00b;
}
.footer {
	position: absolute;
	bottom: 0;
	width: 100%;
  background: red;
}
<div id="outer-wrap">
		<div id="inner-wrap">
			<div class="head">This is head</div>
			<div class="content">This is body</div>
			<div class="footer">This is footer</div>
		</div>
</div>

这是因为当您将 heightwidth 与百分比一起使用时,它会从其父项中获取值,因此如果您没有为 height 设置值 和其父级的 width 无法填充所需的空间。

关于html - 拖车 div 内的粘性页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37543023/

相关文章:

jquery - 在打开页面之前预加载图像

javascript - 删除样式为 ="background-"的 div 元素

html - 如何使用 HTML 和 CSS 创建链接图像悬停?

css - 如何从左到右制作 svg svg 笔划线动画?

javascript - jQuery,在我有一个图像的宽度后只继续脚本一次

javascript - 使用数组值获取 img 文件以在 DIV 元素中使用

javascript - 带有选择输入的 Vue v-model

css - 当 tbody 悬停时改变 thead

javascript - Rails 根据集合选择的值呈现部分

html - SVG 图像标签中的图像未显示在 Chrome 中,而是显示在本地?