html - 如何在贴在顶部的导航栏和贴在底部的页脚之间拉伸 div 高度?
问题描述
我有一个 div 是 bing 地图,我想拉伸它以填充所有高度。对于我刚刚使用的宽度,container-fluid
但高度更棘手,因为导航栏和页脚有一些恒定的高度,当我将地图高度设置为 90vh 时,如果我迟早更改窗口高度,地图将被页脚或导航栏高度覆盖一点可以如果宽度更小,则更改,因为所有文本都不适合一行,并且地图将再次被覆盖一点并显示滚动条。
导航栏位于页面顶部,页脚贴在底部。我不想有滚动条。我想以某种方式将带有地图的 div 锚定到导航栏和页脚,以便它在它们之间完全伸展。有没有办法让上面的 div 保持 10px 的距离,到下面的 div 保持 10px 的距离?所以它会拉伸或收缩以保持它?
如何使用引导程序和/或 css 实现这一目标?
解决方案
像这样的东西
/* Required Stuff */
body {
margin: 0;
height: 100%;
}
#wrapper {
display: grid;
grid-template-rows: 30px 1fr 30px;
}
#content {
height:auto /* or overflow-y: scroll; for fixed header and footer */
}
/* Optional Stuff */
#wrapper {
gap: 1px;
height: 100%;
border: 1px solid black;
background-color: black;
}
#wrapper > * {
padding: 5px;
background-color: white;
}
/* do not copy this into your own projects */
/* stack overflow needs fixed height */
/* just pretend "180px" is just the full page size */
#header {
background-color:green;
}
#footer {
background-color:blue;
}
<body>
<div id="wrapper">
<div id="header">Header Content</div>
<div id="content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<div id="footer">Footer Content</div>
</div>
</body>
推荐阅读
- python - 是否可以输入提示有数字的字符串?
- axon - 聚合和消息是否需要 Axon 中的 hashCode 和 equals?
- angular - 为什么 Ionic 默认不允许复制粘贴?
- vb6 - Chilikat UnlockComponent(有时)在没有 LastErrorText 的情况下返回 0
- twilio - GATHER 动词不解释小/简单的单词,只解释短语
- javascript - 在不刷新页面的情况下更改 URL 参数
- html - div弄乱了布局
- c++ - 在程序启动时选择不同的 QMainWindow 但面临奇怪的 QMessageBox exec() 行为
- azure-application-insights - Azure App Insights:是否可以在警报查询中使用超过 48 小时的时间段或粒度?
- sql-server - 如何根据特定列值从多个表中获取数据