html - bootstrap 4 flex 问题未填充父高度的 100%
问题描述
我试图让一个 2 列网格与占用整个页面高度的 boostrap flex 一起工作。出于某种原因,此代码没有填充 100% 的页面。
body 标签的宽度和高度为 100%。我已经包含了下面的代码片段。没有创建其他 CS。
<div class="d-flex flex-row w-100 h-100 border">
<div class="d-flex flex-column h-100 border ">
test
</div>
<div class="d-flex flex-column h-100 border ">
test
</div>
</div>
解决方案
要使用样式height: 100%
。您需要提供父高度值。如果父高度仍在使用height: 100%
... 直到根(body, html)。您需要将 html 和 body 标签的高度值设置为 100%。
html, body {
height: 100%;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<div class="d-flex flex-row w-100 h-100 border">
<div class="d-flex flex-column h-100 border ">
test
</div>
<div class="d-flex flex-column h-100 border ">
test
</div>
</div>
我已经用一些项目flex-column
为你测试了一个例子。
html, body {
height: 100%;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<div class="d-flex flex-row w-100 h-100 border">
<div class="d-flex flex-column h-100 border ">
<p>Item 1</p>
<p>Item 2</p>
<p>Item 3</p>
</div>
<div class="d-flex flex-column h-100 border ">
<p>Item 1</p>
<p>Item 2</p>
<p>Item 3</p>
</div>
</div>
推荐阅读
- python - python脚本列表或读取值
- gpu - 如何将(pytorch)更大的数据集加载到 GPU 并进行小批量训练?
- javascript - 当我在模拟器中运行时,Framework7 vue 组件未显示。仅显示默认 Cordova 页面
- dictionary - 字典中特定值的平方根
- python - 从 shapely 库中获取变量列表
- typescript - 如何重构此方法以使其更符合 Typescript 的习惯?
- reactjs - 来自 ReactJS 的 Post 请求中未定义的对象值
- android - 如何重置从 Fabric 到 Firebase 的迁移?
- python - 在python中为搜索程序设置目录
- docker - 如何在 bitnami+docker+nginx 中运行网站