正文超出固定导航栏的顶部

新手上路,请多包涵

我有一个固定的导航栏,滚动时会跟随。

但是在标签内滚动文本/图像时,它似乎在导航栏的前面,而不是在后面。

为什么是这样?我该如何解决?

小提琴

 nav {
  background-color: #262626;
  height: 60px;
  width: 100%;
  position: fixed;
  top: 0;
  bottom: 0;
  -webkit-box-shadow: 0px 0px 8px 0px #000000;
  -moz-box-shadow: 0px 0px 8px 0px #000000;
  box-shadow: 0px 0px 8px 0px #000000;
}
nav a {
  font-family: 'Open Sans', sans-serif;
  font-size: 16px;
  line-height: 60px;
  text-transform: uppercase;
  margin: 7px;
}
nav a:link {
  color: #C8C8C8;
  -o-transition: .5s;
  -ms-transition: .5s;
  -moz-transition: .5s;
  -webkit-transition: .5s;
  transition: .5s;
}
nav a:visited {
  color: #C8C8C8;
}
nav a:hover {
  color: #199ABA;
}
#menu {
  margin-right: 375px;
  margin-left: 375px;
  text-align: right;
  margin-top: 0px;
  margin-bottom: 0px;
}
#headertop {
  margin: 0px;
  width: 100%;
  height: 650px;
  font-family: 'Open Sans', sans-serif;
}
#headertop h1 {
  position: absolute;
  margin-left: 375px;
  margin-right: 375px;
  margin-top: 178px;
  line-height: 45px;
  font-size: 50px;
  color: #33CCFF;
  width: 550px;
  height: 100%;
}
 <nav>
  <div id="menu">
    <strong><a href="index.html" style="text-decoration:none">Home</a></strong>
  </div>
</nav>
<div id="headertop">
  <h1>THANKS</h1>
</div>

原文由 Spaccee 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 302
2 个回答

这通常是由您的 z-index 引起的,请确保您输入:

CSS

 z-index: 500 // or whatever number that is a positive real number.

是的,我是对的,请看这个 DEMO

原文由 ARLCode 发布,翻译遵循 CC BY-SA 3.0 许可协议

nav {
    background-color: #262626;
    height: 60px;
    z-index:1; //any higher integer value
    width: 100%;
    position: fixed;
    top: 0;
    bottom: 0;
    -webkit-box-shadow: 0px 0px 8px 0px #000000;
    -moz-box-shadow: 0px 0px 8px 0px #000000;
    box-shadow: 0px 0px 8px 0px #000000;
}

参考 W3Schools 中的 z-index 也参考 CSS-Tricks

原文由 RevanthKrishnaKumar V. 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题