gpt4 book ai didi

html - Bootstrap 4 Scrollable Div 占用屏幕中间剩余高度

转载 作者:行者123 更新时间:2023-12-04 14:17:12 25 4
gpt4 key购买 nike

我正在尝试使用带有 6 个 div 的 Bootstrap 4 设计一个页面,我需要 DIV #4 来占据剩余的高度并可滚动。

Divs 1-3 会略微动态,而不是固定高度。 Div 5 和 6 是一样的。 Div 4 应占据屏幕的剩余部分,但内容可能更长,因此需要滚动。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name=viewport content="width=device-width,initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes" />

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<script src="https://code.jquery.com/jquery-3.3.1.min.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" crossorigin="anonymous"></script>

<style>
html, body {
height: 100%;
margin: 0px;
}
</style>
</head>
<body>
<div class="d-flex flex-column h-100">
<div style="background-color: #000000; width:100%; margin: 0 auto; color: white;">
VARIABLE CONTENT
</div>

<div style="background-color: blue; width:100%; margin: 0 auto;">
<table width="100%">
<tr>
<td style="color: white;">Firstname LastName</td>
<form name="RankingForm" id="RankingForm">
<td>
<select name="Ranking" id="Ranking">
<option>
</select>
</td>
</form>
</tr>
</table>
</div>

<div style="background-color: cyan; width:100%; margin: 0 auto;" class="flex-grow-0">
CONTENT
</div>

<div class="flex-grow-1" style="width:100%; overflow:scroll; margin: 0 auto;">
<div style="width:100%;">
<p>VARIABLE CONTENT THAT COULD BE LONG
<p>VARIABLE CONTENT THAT COULD BE LONG
<p>VARIABLE CONTENT THAT COULD BE LONG
<p>VARIABLE CONTENT THAT COULD BE LONG
<p>VARIABLE CONTENT THAT COULD BE LONG
<p>VARIABLE CONTENT THAT COULD BE LONG
<p>VARIABLE CONTENT THAT COULD BE LONG
<p>VARIABLE CONTENT THAT COULD BE LONG
<p>VARIABLE CONTENT THAT COULD BE LONG
<p>VARIABLE CONTENT THAT COULD BE LONG
<p>VARIABLE CONTENT THAT COULD BE LONG
<p>VARIABLE CONTENT THAT COULD BE LONG
<p>VARIABLE CONTENT THAT COULD BE LONG
<p>VARIABLE CONTENT THAT COULD BE LONG
</div>
</div>

<div class="w-100" style="background-color: #d0d0d0; margin: 0 auto;">
CONTENT
</div>
</body>
</html>

Generated UI, where bottom div is not at the bottom

如有任何帮助,我们将不胜感激。

最佳答案

如评论所示,flexbox是你想要做的三明治风格。但是,我相信它是在 4.1 之后引入的。因此,此解决方案仅在您的 Bootstrap 版本 >= 4.1 时才有效。

您在代码中犯了一些错误。您正在使用内联样式作为类 class="flex-grow: 0" ,您要么将它们放入 style="flex-grow: 0"class="flex-grow-0" .

保持最后一个的固定高度 <div>或其他<div>你想要,你要么给它一个height: somenumberhere pxheight: somenumberhere vh .

<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>


<style>
html, body {
height: 100%;
}
</style>
</head>

<body>
<div class="d-flex flex-column h-100">

<div style="background-color: #000000; width:100%; margin: 0 auto; color: white;">
VARIABLE CONTENT
</div>

<div style="background-color: blue; width:100%; margin: 0 auto;">
<table width="100%">
<tr>
<td style="color: white;">Firstname LastName</td>
<form name="RankingForm" id="RankingForm">
<td>
<select name="Ranking" id="Ranking">
<option>
</select>
</td>
</form>
</tr>
</table>
</div>

<div style="background-color: cyan; width:100%; margin: 0 auto;" class="flex-grow: 0">
CONTENT
</div>

<div class="flex-grow-1" style="width:100%; overflow:scroll; margin: 0 auto;">
<div style="width:100%;">
<p>VARIABLE CONTENT THAT COULD BE LONG
<p>VARIABLE CONTENT THAT COULD BE LONG
<p>VARIABLE CONTENT THAT COULD BE LONG
<p>VARIABLE CONTENT THAT COULD BE LONG
<p>VARIABLE CONTENT THAT COULD BE LONG
<p>VARIABLE CONTENT THAT COULD BE LONG
<p>VARIABLE CONTENT THAT COULD BE LONG
<p>VARIABLE CONTENT THAT COULD BE LONG
<p>VARIABLE CONTENT THAT COULD BE LONG
<p>VARIABLE CONTENT THAT COULD BE LONG
<p>VARIABLE CONTENT THAT COULD BE LONG
<p>VARIABLE CONTENT THAT COULD BE LONG
<p>VARIABLE CONTENT THAT COULD BE LONG
<p>VARIABLE CONTENT THAT COULD BE LONG
</div>
</div>

<div class="w-100" style="background-color: #d0d0d0; margin: 0 auto;">
CONTENT
</div>
</body>

关于html - Bootstrap 4 Scrollable Div 占用屏幕中间剩余高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59057698/

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