【发布时间】:2022-06-24 13:33:11
【问题描述】:
我正在尝试将 DIV 的最小高度设置为容器的 100% 或 100vh。
但是:
将 min-height:100% 设置为 DIV 不起作用并且
将 min-vh-100 类添加到 DIV 使其高度高于父 DIV。
<body class="min-vh-100 d-flex flex-column bg-primary">
<header class="p-3 bg-success">
Header<br/>
Content
</header>
<div class="container flex-grow-1 p-0 bg-secondary">
<div class="d-flex flex-column"><!-- What do I have to do here to set this DIV's height to 100% of parent DIV ? -->
<div class="flex-grow-1 p-3 bg-danger">
Main Content that's need to fill up vertical space
</div>
<div class="p-3 bg-warning">
Bottom Content for Main
</div>
</div>
</div>
<footer class="p-3 bg-info">
Footer<br/>
Content<br/>
© 2022 Bootstrap
</footer>
</body>
这就是我想要的:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Footer at Bottom when content is not page-full</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
</head>
<body class="min-vh-100 d-flex flex-column bg-primary">
<header class="p-3 bg-success">
Header<br/>
Content
</header>
<div class="container flex-grow-1 p-0 bg-secondary">
<div class="d-flex flex-column">
<div class="flex-grow-1 p-3 bg-danger">
Main Content
</div>
<div class="p-3 bg-warning">
Bottom Content for Main
</div>
</div>
</div>
<footer class="p-3 bg-info">
Footer<br/>
Content<br/>
© 2022 Bootstrap
</footer>
</body>
</html>
【问题讨论】:
标签: flexbox bootstrap-5