html - 如何使 body 元素扩展到 html 元素的大小?
问题描述
我希望正文随着页面变大而扩展。我尝试将 body 的高度设置为 100%,将 html 元素的高度设置为 100%,但它没有按预期工作:
蓝色代表正文,红色代表 html 元素
我希望正文覆盖整个 html 元素。这就是我在 css 中的代码:
html {
font-family: Palatino, 'Palatino Linotype', serif;
background-color: red;
height: 100%;
margin: 0;
padding: 0;
}
body {
background-color: blue;
height: 100%;
margin: 0;
padding: 0;
}
我希望有一个人可以帮助我!
解决方案
不要将高度更改为 100%,而是尝试将其更改为 height: auto; 这会自动将高度调整为其中的内容。
如果高度设置为数值(如像素、(r)em、百分比),那么如果内容不适合指定的高度,它将溢出。
希望能帮助到你
推荐阅读
- python - 如何使用 Selenium webdriver 将日期发送到只读日历输入框?
- node.js - driver.hideKeyboard(); 在 iOS 上不可用,但我可以在 Android 上使用它并且工作正常
- web-services - WebSphere SOAP Web 服务间歇性地获取 java.net.SocketTimeoutException: Read timed out and the server down
- git - git check-format 找不到指定的路径
- cron - Cron Job 运行速度极慢
- java - 如何为 java 和 python 设置 bash 路径
- node.js - 运行编译的打字稿时未定义导出
- javascript - 在javascript中获取两个日期之间的周数的问题
- python - 为第一个标准输入选择哪个插槽和哪个信号?
- flutter - Flutter:解析 Firebase 实时数据库快照以列出