html - 负底边距“粘滞页脚”有烦人的垂直滚动条,如果涉及要素
问题描述
我有一个用“负底部边距”技术实现的粘性页脚(不使用 flex,因为需要支持 IE)
它工作正常,直到我有一些类似<h>
或其中<p>
的元素,然后它呈现一个令人讨厌的垂直滚动条。
我的临时解决方法是<span>
改用,但布局会明显不同。这里最好的解决方案是什么?
html,
body,
form {
height: 100%;
margin: 0;
}
.wrapper {
min-height: 100%;
/* Equal to height of footer */
/* But also accounting for potential margin-bottom of last child */
margin-bottom: -30px;
}
.footer,
.push {
height: 30px;
}
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<form>
<div class="wrapper">
<h1>I am the header</h1><!--I needs to use span here-->
<div class="push"></div>
</div>
<footer class="footer">
<p>I am the footer</p><!--I needs to use span here-->
</footer>
</form>
</body>
</html>
解决方案
.footer, .push { height: 30px; }
这是您将页脚高度限制为 30 像素的问题,如果您输入的文本超过 30 像素,浏览器将自动滚动它以显示所有内容,尝试将其增加到 60 像素。
推荐阅读
- java - Java + SpringBoot + Neo4j:有没有办法绕过 OGM?
- javascript - JQuery 重复字段在删除行时与 Bootstrap 布局混淆
- python-3.x - Mac OS 上的 Pip 安装出错:命令“/usr/bin/clang”失败,退出代码为 1
- linux - 将 find & exec 的输出重定向到日志文件
- java - 将内部带有 var 的 for each 循环转换为 Java Stream?
- c# - C#按钮单击,显示图像然后退出
- vue.js - 使用日期选择器 Vuetify 动态表单输入
- android - Codetrix 电容器 google 登录需要登录时的选项
- typescript - 如何为现有属性的 TypeScript 接口添加别名?
- sapui5 - 当只剩下一个选择项时如何禁用 sap.m.Select