在这种情况下如何正确使用z-index?

问题描述 投票:0回答:1

我需要我的h1“Мышонок”在单击汉堡菜单时保持完全可见。

当我单击菜单时,我的白色h1出现在菜单后面,我不知道如何使其100%可见。

我试图弄乱z-index,但很不幸。菜鸟在这里。请帮助

@import url("https://fonts.googleapis.com/css?family=Oswald:200,300,400,500,600,700&display=swap");
* {
  margin: 0px;
  padding: 0px;
  box-sizing: border-box;
}

body {
  font-family: "Oswald", sans-serif;
}

img {
  width: 100%;
  height: auto;
}


/* Utility */

.container {
  margin: 0 auto;
  max-width: 1160px;
  padding: 0 20px;
  overflow: hidden;
}

.overlay {
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  position: absolute;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 999;
}

.hidden {
  display: none;
}


/* Home */

.showcase {
  position: relative;
  height: 100vh;
  background-image: url(../img/homebg/bg1.jpg);
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  animation: slide 18s infinite;
  transition: 100ms ease-in-out;
  width: 100%;
}

.showcase h1 {
  font-size: 3.5rem;
  font-weight: 500;
  color: #fff;
  padding-top: 40px;
  text-transform: uppercase;
  z-index: 1001;
}

@keyframes slide {
  0% {
    background-image: url(../img/homebg/bg1.jpg);
  }
  20% {
    background-image: url(../img/homebg/bg2.jpg);
  }
  40% {
    background-image: url(../img/homebg/bg3.jpg);
  }
  60% {
    background-image: url(../img/homebg/bg4.jpg);
  }
  80% {
    background-image: url(../img/homebg/bg5.jpg);
  }
  100% {
    background-image: url(../img/homebg/bg1.jpg);
  }
}

.menu-wrap {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1001;
  width: 100%;
  height: 100%;
}

.menu-wrap .toggler {
  position: absolute;
  top: 55px;
  right: 280px;
  z-index: 1002;
  cursor: pointer;
  width: 50px;
  height: 50px;
  opacity: 0;
}

.menu-wrap .hamburger {
  position: absolute;
  top: 55px;
  right: 270px;
  z-index: 1001;
  width: 70px;
  height: 60px;
  padding: 1rem;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}


/* Hamburger Icon */

.menu-wrap .hamburger>div {
  position: relative;
  flex: none;
  width: 100%;
  height: 4px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.4s ease;
}

.menu-wrap .hamburger>div::before,
.menu-wrap .hamburger>div::after {
  content: "";
  position: absolute;
  z-index: 1;
  top: -10px;
  width: 100%;
  height: 4px;
  background: inherit;
}

.menu-wrap .hamburger>div::after {
  top: 10px;
}


/* Toggler Animation */

.menu-wrap .toggler:checked+.hamburger>div {
  transform: rotate(135deg);
}

.menu-wrap .toggler:checked+.hamburger>div:before,
.menu-wrap .toggler:checked+.hamburger>div:after {
  top: 0;
  transform: rotate(90deg);
}

.menu-wrap .toggler:checked:hover+.hamburger>div {
  transform: rotate(225deg);
}


/* Show Menu */

.menu-wrap .toggler:checked~.menu {
  visibility: visible;
}

.menu-wrap .toggler:checked~.menu>div {
  transform: scale(1);
  transition-duration: 0.75;
}

.menu-wrap .toggler:checked~.menu>div>div {
  opacity: 1;
  transition: opacity 0.1s ease 0.1s;
}


/* Menu overlay */

.menu-wrap .menu {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  visibility: hidden;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.menu-wrap .menu>div {
  background: rgba(0, 0, 0, 0.5);
  width: 200vw;
  height: 200vw;
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  transform: scale(0);
  transition: all 0.4s ease;
  border-radius: 50%;
}

.menu-wrap .menu>div>div {
  text-align: center;
  max-width: 90vw;
  max-height: 100vh;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.menu-wrap .menu>div>div>ul>li {
  list-style: none;
  font-size: 3rem;
  padding: 1rem;
}

.menu-wrap .menu>div>div>ul>li>a {
  color: #fff;
  text-decoration: none;
}
<div class="hidden">
  <img src="img/homebg/bg2.jpg" />
  <img src="img/homebg/bg3.jpg" />
  <img src="img/homebg/bg4.jpg" />
  <img src="img/homebg/bg5.jpg" />
</div>

<!-- Home -->
<div class="showcase">
  <div class="overlay">
    <div class="container">
      <h1>Мышонок</h1>
      <!-- Hamburger -->
      <div class="menu-wrap">
        <input type="checkbox" class="toggler" />
        <div class="hamburger">
          <div></div>
        </div>
        <div class="menu">
          <div>
            <div>
              <ul>
                <li><a href="personal.html">Personal</a></li>
                <li><a href="men.html">Men</a></li>
                <li><a href="women.html">Women</a></li>
                <li><a href="video.html">Video</a></li>
                <li><a href="about.html">About</a></li>
              </ul>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

我不知道要添加什么更多的细节,stackoverflow,我相信我已经尽我所能描述了它

html css z-index
1个回答
0
投票

这是我想出的解决您的问题的方法:https://jsfiddle.net/L7ac6j3v/7/

[我认为您面临的主要问题之一是过度使用疯狂的z-index值(例如999到1005等)来使它复杂化,您将看到我已经删除了许多值或将其替换为易于使用的值像1,2等

[我看到的另一个主要问题是您使用position样式而在尝试使用元素的position: absolute时没有z-index

作为旁注,我要测试元素是否正确放置的一种方法是使用cursor: pointerpointer-events

希望这会有所帮助:)

© www.soinside.com 2019 - 2024. All rights reserved.