html - 固定导航栏落后于内容

标签 html css navbar fixed

我这里有一个固定的导航栏。

问题是,当你向下滚动时,如果你将鼠标悬停在一个基本上位于导航栏后面的元素上,它就会变成导航栏的顶部?

很奇怪?

有什么建议吗?

CSS:

    html, body {
    margin: 0;
    padding: 0;
    font-family: 'Open Sans', sans-serif;
    background-color: #fff; }

    .container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px; }

    nav {
    background-color: #fff;
    height: 40px;
    position: fixed;
    top: 0;
    width: 100%;
    float: left; }
    nav .links {
    float: left;
    font-size: 13px;
    font-weight: 600;
    margin-top: 10px; }
    nav .links a {
    color: #000;
    text-decoration: none;
    margin-right: 10px;
    transition: .15s; }
    nav .links a:hover {
    opacity: 0.6;
    transition: .15s; }
    nav .name {
    float: right;
    margin-top: 10px; }
    nav .name a {
    color: #000;
    text-decoration: none; }
    nav .name a h2 {
    font-size: 14px;
    margin: 0; }

    .work {
    font-size: 0;
    padding-top: 40px;
    overflow: hidden; }
    .work img {
    max-width: 20%;
    transition: .15s; }
    .work img:hover {
    opacity: .8;
    transition: .15s; }

JSFiddle:http://jsfiddle.net/2c53e1eg/

最佳答案

z-index: 9; 添加到 nav

html,
body {
  margin: 0;
  padding: 0;
  font-family: 'Open Sans', sans-serif;
  background-color: #fff;
}
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}
nav {
  background-color: #fff;
  height: 40px;
  position: fixed;
  top: 0;
  width: 100%;
  float: left;
  z-index: 9;
}
nav .links {
  float: left;
  font-size: 13px;
  font-weight: 600;
  margin-top: 10px;
}
nav .links a {
  color: #000;
  text-decoration: none;
  margin-right: 10px;
  transition: .15s;
}
nav .links a:hover {
  opacity: 0.6;
  transition: .15s;
}
nav .name {
  float: right;
  margin-top: 10px;
}
nav .name a {
  color: #000;
  text-decoration: none;
}
nav .name a h2 {
  font-size: 14px;
  margin: 0;
}
.work {
  font-size: 0;
  padding-top: 40px;
  overflow: hidden;
}
.work img {
  max-width: 20%;
  transition: .15s;
}
.work img:hover {
  opacity: .8;
  transition: .15s;
}
<nav>

  <div class="container">

    <div class="links">

      <a href="#">WORK</a>
      <a href="#">ABOUT</a>
      <a href="#">DRIBBBLE</a>
      <a href="#">BEHANCE</a>
      <a href="#">BLOG</a>
      <a href="#">CONTACT</a>

    </div>

    <div class="name">

      <a href="#"><h2>Tom Walsh</h2></a>

    </div>

  </div>

</nav>

<div class="work">

  <a href="#">
    <img src="http://placehold.it/500x500">
  </a>
  <a href="#">
    <img src="http://placehold.it/500x500">
  </a>
  <a href="#">
    <img src="http://placehold.it/500x500">
  </a>
  <a href="#">
    <img src="http://placehold.it/500x500">
  </a>
  <a href="#">
    <img src="http://placehold.it/500x500">
  </a>
  <a href="#">
    <img src="http://placehold.it/500x500">
  </a>
  <a href="#">
    <img src="http://placehold.it/500x500">
  </a>
  <a href="#">
    <img src="http://placehold.it/500x500">
  </a>
  <a href="#">
    <img src="http://placehold.it/500x500">
  </a>
  <a href="#">
    <img src="http://placehold.it/500x500">
  </a>
  <a href="#">
    <img src="http://placehold.it/500x500">
  </a>
  <a href="#">
    <img src="http://placehold.it/500x500">
  </a>
  <a href="#">
    <img src="http://placehold.it/500x500">
  </a>
  <a href="#">
    <img src="http://placehold.it/500x500">
  </a>
  <a href="#">
    <img src="http://placehold.it/500x500">
  </a>
  <a href="#">
    <img src="http://placehold.it/500x500">
  </a>
  <a href="#">
    <img src="http://placehold.it/500x500">
  </a>
  <a href="#">
    <img src="http://placehold.it/500x500">
  </a>
  <a href="#">
    <img src="http://placehold.it/500x500">
  </a>
  <a href="#">
    <img src="http://placehold.it/500x500">
  </a>

</div>

关于html - 固定导航栏落后于内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31693041/

相关文章:

css - Bootstrap3 - 让导航栏元素占据整个宽度

javascript - 我有一张被 svg 遮盖的图像,我想让图像的遮盖部分不可点击

javascript - 如何选择被点击的行

javascript - 过滤动态html表格

html - 将 bootstrap 放入 header.php , footer.php 等

javascript - 图片随机放置在页面上

html - Bootstrap (3.3.7) 移动导航栏元素(链接)不工作

javascript - CSS/Javascript 下拉菜单问题

javascript - 在 div 上完成多次点击时 onclick() 事件的问题

javascript - Vuetify 右对齐按钮组