html - 具有绝对位置的菜单隐藏在其他元素下

标签 html css css-position absolute

我有汉堡菜单,当我点击它时,它会向下推送内容。 我想阻止它,所以我已经添加到事件类position:absolute,但是菜单隐藏在其他元素下。 我尝试使用 z-index 但它对此不起作用。 我做错了什么?

这是一个codepen https://codepen.io/anon/pen/dEbgvJ

body,
html {
  margin: 0;
  padding: 0;
  font-family: Arial,
    Helvetica,
    sans-serif;
}

ul {
  padding-left: 0;
}

* {
  box-sizing: border-box;
}

h1 {
  margin: 0;
}

.page-header {
  background-color: #87509c;
  width: 100%;
  height: 80vh;
}

.navbar {
  font-size: 18px;
  background: #87509c;
  padding-bottom: 10px;
}

.main-nav {
  list-style-type: none;
  display: none;
}

.nav-links {
  text-decoration: none;
  color: #ffffff;
  text-transform: uppercase;
  font-family: Arial;
  font-size: 16px;
}

.main-nav li {
  text-align: center;
  margin: 15px auto;
}

.navbar-toggle {
  position: absolute;
  top: 22px;
  right: 20px;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.8);
  font-size: 24px;
}

.active {
  display: block;
  position: absolute;
  left: 0;
  right: 0;
  z-index: 100;

}

.logo {
  margin-left: 10px;
  margin-top: 10px;
}

@media screen and (min-width: 768px) {
  .page-header {
    display: flex;
    justify-content: space-around;
    background-color: #87509c;
    width: 100%;
    height: 600px;
  }

  .navbar {
    display: flex;
    justify-content: space-between;
    padding-bottom: 0;
    height: 70px;
    align-items: center;
    width: 1000px;
  }

  .main-nav {
    display: flex;
    margin-right: 30px;
    flex-direction: row;
    justify-content: flex-end;

  }

  .main-nav li {
    margin: 0;
  }

  .nav-links {
    margin-left: 40px;
  }

  .navbar-toggle {
    display: none;
  }

  .nav-links:hover {
    color: rgba(255, 255, 255, 1);
  }
}

.content-container {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  height: 300px;
}

.header-text {
  font-size: 16px;
  text-align: center;
  color: #fff;
  font-weight: 600;
  width: 200px;
  display: block;
  margin: 0 auto;
}

.button-work {
  font-size: 15px;
  font-weight: 300;
  border-radius: 3px;
  color: #fff;
  text-transform: uppercase;
  margin: 0 auto;
  display: block;
  border: none;
  height: 35px;
  width: 150px;
  background: #EB7D4B;
}

最佳答案

菜单没有隐藏,没有背景颜色所以它是透明的。文字是白色的,所以很难看清。所以只要给 .man_nav 类添加一个背景色就可以了。

关于html - 具有绝对位置的菜单隐藏在其他元素下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55981716/

相关文章:

javascript - 在 Angular2 上使用正则表达式制作管道

javascript - 分辨率相关的移动模板

html - 固定在移动设备上的背景

css - 如何使用 Skeleton Boilerplate 在 div 中居中图像

css - 如何将位置固定的 div 设置为居中对齐?

php - 如何通过 symfony 爬虫获取当前父节点之后的下一个节点?

javascript - 使用 jquery 循环遍历 div 中的子项并制作动画

html - 如何将 'overflow: scroll' 与动态大小的 div 容器一起使用?

html - 使用内联 block 将垂直对齐应用于两个 div

css - 将表格并排放置