html - 如何创建一个占据整个屏幕并在滚动时折叠到标题的div
问题描述
我想创建一个跨越我设备的整个空间的 div,就像示例站点一样
我尝试做的是创建一个具有固定高度的标题,但无法在标题下方创建 div 以跨越剩余高度。
//Fixed Header
.fixed-nav {
position: fixed;
width: 100%;
height: 69px;
background-color: #f2333a;
}
.x-div {
position: relative;
height: 100%;
background-color: #F2333A;
z-index: 10;
}
解决方案
如果您希望导航下方的 div 跨越剩余高度,请使用height: calc(100vh - 69px)
69px 可以是任何固定高度对象的高度。
body {
margin: 0;
}
.container {
width: 100%;
height: 100vh;
position: relative;
}
.fixed-nav {
width: 100%;
height: 69px;
background-color: red;
color: white;
position: fixed;
top: 0;
left: 0;
z-index: 1000;
}
.header {
width: 100%;
height: calc(100vh - 69px);
position: absolute;
left: 0;
bottom: 0;
background-color: red;
z-index: 1;
margin: 0;
}
.more-content {
height: 100vh;
width: 100%;
margin: 20px;
}
<div class="container">
<nav class="fixed-nav">NAV</nav>
<header class="header"></header>
</div>
<div class="more-content">Rest of webpage
</div>
推荐阅读
- asp.net - 通过asp.net中的服务帐户打开文件时出错
- phpstorm - php.ini 文件中的 xdebug_break 和 start_with_request - 未按预期工作
- javascript - “价值!==价值”什么时候是真的?
- angular - FormGroup 已弃用
- python - 使用 Python 检测音频文件非语音部分的开始和结束时间
- asp.net-core - 动态配置数据表项模板槽
- python - 机器学习中 3D numpy 数组图像的特征检测
- swift - UITextField 检查用户是否输入了数字
- snowflake-cloud-data-platform - 如何从 SNWOFLAKE 环境中创建的表中获取原始 DDL?
- blockchain - Remix IDE - 部署智能合约时出现功能问题