我正在使用 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 https://plnkr.co/edit/GQHoephQyx3hoejgkT4k?p=preview
使用 Bootstrap 4.0 根据需要显示页面的正确方法是什么,即使用图像根据屏幕尺寸缩小/增大时留下的完整剩余高度?
EDIT为了澄清:
内容本身应该有一个滚动条,但不是整个页面。 IE。带有图像的标题和菜单栏应始终保持可见,而随后出现的内容应有滚动条(如有必要)。
使用 flexbox 使内容区域填充其父容器(在本例中为主体)的高度,而不是设置定义的高度。
body {
display:flex;
flex-direction:column;
}
.flex-fill {
flex: 1 1 auto;
}
.flex-shrink {
flex-shrink: 0;
}
https://codeply.com/go/fKNRvG0Hak https://codeply.com/go/fKNRvG0Hak
Note: The flex-fill
实用程序类将包含在下一个 Bootstrap 4.2 版本中:https://github.com/twbs/bootstrap/commit/2137d61eacbd962ea41e16a492da8b1d1597d3d9 https://github.com/twbs/bootstrap/commit/2137d61eacbd962ea41e16a492da8b1d1597d3d9
类似问题:
Bootstrap 4使用flex-grow使嵌套行填充父级以填充视口高度 https://stackoverflow.com/questions/48927663
Bootstrap 4 导航栏和内容填充高度弹性框 https://stackoverflow.com/questions/49191957
Bootstrap 导航栏上方的 4 页宽标题栏 https://stackoverflow.com/questions/48703632
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)