Bootstrap 4.0 - 带有图像 + 导航栏 + 全高正文的响应式标头



我正在使用bootstrap 4构建一个响应式页面,该页面具有标题/标题部分,其中包含客户徽标,名称和导航栏的图像。所有这些元素都是响应式的,即图像根据屏幕尺寸缩小,导航栏在小屏幕上最小化。

现在我想让身体也以响应的方式。 即:用内容填充屏幕的剩余高度,必要时使用滚动条显示所有内容。
但是由于某种原因,我无法弄清楚如何在整个高度上跨越页面的其余部分。当它非常适合移动设备时,它要么在某些较大的屏幕上太大,要么非常适合大屏幕,但高度只有移动设备应有的一半。

该页面大致使用以下结构构建:

<!DOCTYPE html>
<html lang="de" style="height:100%">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>Client Name</title>
</head>
<body class="main" style="height:100%">
<div class="container">
<div class="text-center">
<!-- Client image goes here -->
<h1 style="display:inline;margin-left:0.6em;color:#8b7d7b">Client Name</h1>
</div>
</div>
<nav class="navbar navbar-expand-lg navbar-light" style="background-color:#e0eee0">
<button class="navbar-toggler collapsed" type="button" data-toggle="collapse" data-target="#mainnavbar" aria-controls="mainnavbar" aria-expanded="false" aria-label="Toggle Navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div id="mainnavbar" class="navbar-collapse collapse justify-content-md-center">
<ul class="navbar-nav">
<li class="nav-item nav-link active">Page A</li>
</ul>
</div>
</nav>
<div class="container" style="height:70vh">
<div class="row" style="height:100%">
<!-- Main body of page -->
<div class="col-sm-1 col-md-9" style="height:100%">
<p class="col-scrol">
<!-- Main part of the page. Content should have full height and scroll vertically if necessary -->
</p>
</div>
<!-- Comment section (scrolling) -->
<div class="d-none d-md-block col-md-3 comment-section">
<!-- Comment section at the left hand side of the page -->      
</div>
</div>
</div>
</body>
</html>

我创建了一个实际上显示整个页面的 plunkr:
https://plnkr.co/edit/GQHoephQyx3hoejgkT4k?p=preview

使用bootstrap 4.0,根据需要显示页面的正确方法是什么,即使用图像根据屏幕尺寸缩小/增长时剩余的完整高度?

编辑澄清:
内容本身应该有一个滚动条,而不是整个页面。 即带有图像和菜单栏的标题应始终保持可见,而之后的内容应在必要时具有滚动条。

不要设置定义的高度,而是使用 flexbox 使内容区域填充其父容器(在本例中为正文)的高度。

body {
display:flex;
flex-direction:column;
}
.flex-fill {
flex: 1 1 auto;
}
.flex-shrink {
flex-shrink: 0;
}

https://codeply.com/go/fKNRvG0Hak

注意:flex-fill实用程序类将包含在下一个 Bootstrap 4.2 版本中:https://github.com/twbs/bootstrap/commit/2137d61eacbd962ea41e16a492da8b1d1597d3d9


类似问题:
引导 4 使嵌套行填充父级已使用弹性增长
填充视口高度 引导程序 4 导航栏和内容填充高度弹性框
引导程序 4 导航栏上方的页面宽标题栏

最新更新