html - 身体隐藏在固定导航后面
问题描述
我希望固定导航 div 与主 div 对接,我尝试使用 % 添加边距,这会有所帮助,但随着浏览器的缩小,我必须使用 @media 来调整它。有没有办法只用css得到这个?并且不使用 jscript
#fixednav{
background-color:#00AFEA !important;
border: px solid blue;
min-height:100px;
position: fixed;
top: 0px;
width: 100%;
z-index:1;box-shadow: 0px 0.5px 0px BLACK;
}
.main {
border: px solid blue;
z-index:2;width: 100%;
margin-top: 5%;
}
<div id="fixednav">
nav goes here and z index is 1 and the content is hidden as this div is covering it up
</div><!--fixed nav-->
<!--fixednav should rest against main not behind it-->
<div class="main">
content goes here and z index is 2
</div><!--main-->
解决方案
你需要一个相对于.main
div 的位置。
注意:z-index 仅适用于定位元素(位置:绝对、位置:相对或位置:固定)。
— W3学校
#fixednav{
background-color:#00AFEA !important;
border: px solid blue;
min-height:100px;
position: fixed;
top: 0px;
width: 100%;
z-index:1;box-shadow: 0px 0.5px 0px BLACK;
}
.main {
position: relative;
border: px solid blue;
z-index:2;width: 100%;
margin-top: 5%;
}
<div id="fixednav">
nav goes here and z index is 1 and the content is hidden as this div is covering it up
</div><!--fixed nav-->
<!--fixednav should rest against main not behind it-->
<div class="main">
content goes here and z index is 2
</div><!--main-->
推荐阅读
- c# - rdlc 报告行总计字段计算不正确
- msbuild - 如何使用 msbuild 命令行创建包但排除测试项目
- reactjs - 如何在静态函数 React native 中设置状态
- canvas - 缩放后paperjs添加点的问题
- javascript - 如何从 javaScript 对象中删除值?
- assembly - ARM 汇编,操作变量
- database - 创建用于连接 Power BI 的平面数据库
- javascript - 悬停显示子元素,失去焦点时隐藏
- c# - Winforms 静态 HandleCreated 或 OnLoad 事件
- mathematical-optimization - 如何在 CPLEX 中使用决策变量进行 if 语句