如何使用 z 索引管理交错图层



我在管理多个交错层时遇到了一些困难。

我在这个 Plunker 示例中重现了我的问题

  <body>
<header>
  <nav class="navbar">
      <ul class="navbar-nav">
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle" href="http://example.com" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            Dropdown link
          </a>
          <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
            <a class="dropdown-item" href="#">Action</a>
            <a class="dropdown-item" href="#">Another action</a>
            <a class="dropdown-item" href="#">Something else here</a>
          </div>
        </li>
      </ul>
  </nav>
</header>
<nav class="navbar row filter">
  <form class="form-inline">
    <input name="search" class="form-control" type="text" size="30"/>
  </form>
</nav>

header {
  background-repeat: no-repeat;
  background-position: top center;
  background-size: 100%;
  position: relative;
  height: 80px;
  z-index: 100;
}
header .navbar {
  padding:0;
}
.dropdown-menu {
  z-index:300;
}
.filter {
  margin-top:-20px;
  background-color: black;
}
.filter form {
 z-index:200;
}

如果我从最远的元素开始,我应该有:

  1. 筛选器栏容器
  2. 标头容器
  3. 筛选器栏内容(输入(
  4. 标题内容(菜单(

所以我指定:

  • Z 索引为 100 的标题将鼠标悬停在筛选器栏上
  • 将 Z 索引为 200 的筛选器栏内容悬停在标题上
  • 带有 Z 索引 300 的下拉菜单可查看所有组件...这个不起作用,它停留在过滤器栏内容下....为什么?

我不是 css 方面的专家,也许有更好的方法可以实现此设计,但我不明白为什么下拉菜单不覆盖所有组件?

简单:)您只需要在标题和导航栏之间调整z索引即可。

header {
  z-index: 301;
}
navbar{
  z-index: 300;
}

玩得愉快

编辑:了解了你到底想要什么之后,你可以看看这个

您需要

从标题中删除 z 索引并将 z 索引添加到导航栏,如下所示

header {
  background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAyAAAABkCAYAAAB+UVSPAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAZdEVYd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ZJiGSCSJEmSYhkgkiRJkmIZIJIkSZJiGSCSJEmSYhkgkiRJkmIZIJIkSZJifQyQN0mSFO/jH/Hpu6RsbjHc690jSZKyPd/+ed7e3iSV+7jF043qYs8jSZLi/fj//Q9Q9+sWz3eqKx0/SpKkyxkgsMEAiXf8KEmSLmeAwAYDJN7xoyRJupwBAhsMkHjHj5Ik6XIGCGwwQOIdP0qSpMsZILDBAIl3/ChJki5ngMAGAyTe8aMkSbqcAQIbDJB4x4+SJOlyBghsMEDiHT9KkqTLGSCwwQCJd/woSZIuZ4DABgMk3vGjJEm6nAECGwyQeMePkiTpcgYIbDBA4h0/SpKkyxkgsMEAiXf8KEmSLmeAwAYDJN7xoyRJupwBAhsMkHjHj5Ik6XIGCGwwQOIdP0qSpMsZILDBAIl3/ChJki5ngMAGAyTe8aMkSbqcAQIbDJB4x4+SJOlyBghsMEDiHT9KkqTLGSCwwQAJ97x+AgOVhW80idDhAAAAAElFTkSuQmCC);
  background-repeat: no-repeat;
  background-position: top center;
  background-size: 100%;
  position: relative;
  height: 80px;
}
navbar{
   z-index: 100;
}

相关内容

  • 没有找到相关文章

最新更新