gpt4 book ai didi

css - 如果 div 比视口(viewport)短,则扩展它的高度

转载 作者:行者123 更新时间:2023-11-28 02:11:00 25 4
gpt4 key购买 nike

我有一个包含三个选项卡和一个页脚的 div,问题是如果其中一个选项卡的内容小于视口(viewport),则页脚下方会出现一个空白区域。 This is one of the tabs working fine.

And this is what happens when I switch the tab

我需要那个 div 延伸到底部,但我找不到办法做到这一点

以下是我的代码:

<html>
<head>
<style>
html, body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
}
</style>
</head>
<body style="padding-top: 3.5rem;">
<navbar>
Navbar
</navbar>
<div class="container" style="width:100%;display:block;overflow:auto;">
Tabs and everything else
</div>
<footer class="py-5 bg-dark" style="position: relative;bottom: 0;width: 100%;">
Footer
</footer>
</body>
</html>

顺便说一下,我使用的是 Bootstrap 4

最佳答案

如果你给你的页眉和页脚一个特定的高度,比如说 40px,那么你可以给你的 div min-height: calc(100%-80px)。这将使它占据其父级的整个高度减去页眉和页脚的高度。我添加了背景颜色只是为了演示:

<html>
<head>
<style>
html, body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
}
</style>
</head>
<body style="padding-top: 3.5rem;">
<navbar style="background-color: yellow; display: block; height: 40px;">
Navbar
</navbar>
<div class="container" style="width: 100%; min-height: calc(100% - 80px); display: block; overflow: auto; background-color: cyan;">
Tabs and everything else
</div>
<footer class="py-5 bg-dark" style="position: relative; bottom: 0; width: 100%; height: 40px; background-color: yellow;">
Footer
</footer>
</body>
</html>

关于css - 如果 div 比视口(viewport)短,则扩展它的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48758994/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com