html - 悬停在使用位置 : absolute? 的按钮上不起作用

标签 html css

我尝试使用 z-index 在着陆页上的标题/按钮的背景中放置一个图像(因为我使用背景颜色来创建叠加层),但是在我定位标题之前我无法让它工作/按钮作为绝对。现在无法悬停或选择按钮(显然需要单击)。

着陆页被分成两半,我没有将背景图片放在下半部分,按钮悬停很好,但在上半部分我留下了背景图片,我无法将鼠标悬停在按钮上。如果您找到解决方案,请解释我是如何误解的。

http://codepen.io/levane/pen/NNBOdM?editors=1100

<body>
    <section id="landing-page">
      <nav>
        <button id="contact">Contact</button>
      </nav>
      <div id="top-half">
        <header>
          <h1>Artemis Levane</h1>
          <h2>Web Designer & Front-End Developer</h2>
          <button id="about-btn">Who I Am</button>
        </header><img src="https://images.unsplash.com/photo-1442328166075-47fe7153c128?ixlib=rb-0.3.5&amp;q=80&amp;fm=jpg&amp;crop=entropy&amp;s=e18fcc3c0c7149c8ce315a176be812f0"/>
  </div>
  <div id="bottom-half">
    <header>
      <h3>Helping businesses & individuals bring their brands to the web</h3>
      <button id="work-btn">What I Do</button>
    </header><img src="/Personal/Images/Logo.png"/><br/>
    <div id="bounce">
      <button id="finger">☟</button>
    </div>
  </div>
</section>

* {
  margin: 0;
  padding: 0;
  border: 0;
  outline: 0;
  font-size: 100%;
  vertical-align: baseline;
  background: transparent;
  font-family: Antonio;
}

#landing-page {
  text-transform: uppercase;
}

nav {
  width: 100%;
  position: absolute;
}

button {
  font-family: Antonio;
  text-transform: uppercase;
}

#top-half {
  height: 340px;
  background: rgb(27, 40, 57);
  color: rgb(240, 202, 0);
  overflow: hidden;
}

#top-half header {
  width: 50%;
  height: 340px;
  overflow: hidden;
  margin-left: 25%;
  margin-top: 5%;
  text-align: center;
  position: absolute;
}

#top-half img {
  width: 100%;
  opacity: 0.1;
}

#landing-page header h1 {
  font-weight: 100;
  font-size: 500%;
  letter-spacing: 5px;
}

#landing-page header h2 {
  font-size: 23;
  font-weight: 400;
  letter-spacing: 3px;
  opacity: 0.7;
}

#about-btn {
  border: 5px solid rgb(240, 202, 0);
  padding: 5px 40px;
  color: rgb(240, 202, 0);
  letter-spacing: 4px;
  margin-top: 5%;
}

#about-btn:hover {
  color: rgb(27, 40, 57);
  background: rgb(240, 202, 0);
}

#contact {
  padding: 5px 40px;
  color: rgb(240, 202, 0);
  border: 3.5px solid rgb(240, 202, 0);
  border-radius: 25px;
  font-weight: 100;
  letter-spacing: 3px;
  text-align: center;
  font-size: 15px;
  margin-left: 87%;
  margin-top: 1.1%;
}

#contact:hover {
  color: rgb(27, 40, 57);
  background: rgb(240, 202, 0);
}

#bottom-half {
  height: 340px;
  background-color: rgb(255, 246, 222);
  color: rgb(27, 40, 57);
}

#bottom-half header {
  position: absolute;
  width: 60%;
  margin-left: 24.8%;
  margin-top: 7%;
}

#bottom-half header h3 {
  font-size: 50px;
  font-weight: 100;
  letter-spacing: 3px;
}

#bottom-half img {
  height: 87%;
  margin-left: 470.5px;
  margin-top: 2.5%;
  opacity: .1;
}

#work-btn {
  border: 5px solid rgb(27, 40, 57);
  padding: 5px 40px;
  color: rgb(27, 40, 57);
  letter-spacing: 4px;
  margin-left: 29.7%;
  margin-top: 3%;
  font-weight: 400;
}

#work-btn:hover {
  color: rgb(255, 246, 222);
  background: rgb(27, 40, 57);
}

/*   ☟  FINGER BOUNCE  ☟   */

@keyframes bounce {
  0%, 20%, 50%, 80%, 100% {
    -moz-transform: translateY(0);
    -ms-transform: translateY(0);
    -webkit-transform: translateY(0);
    transform: translateY(0);
  }
  40% {
    -moz-transform: translateY(-20px);
    -ms-transform: translateY(-20px);
    -webkit-transform: translateY(-20px);
    transform: translateY(-20px);
  }
  60% {
    -moz-transform: translateY(-15px);
    -ms-transform: translateY(-15px);
    -webkit-transform: translateY(-15px);
    transform: translateY(-15px);
  }
}

#finger {
  margin-top: -10%;
  font-size: 35px;
}

#bounce {
  -moz-animation: bounce 4s infinite;
  -webkit-animation: bounce 4s infinite;
  animation: bounce 4s infinite;
}


/*   END FINGER BOUNCE   */

最佳答案

您可以通过设置更高的 z-index 来增加堆叠顺序值(value)。

nav {
  ...
  position: absolute;
  z-index: 1;
}
#top-half header {
  ...
  position: absolute;
  z-index: 1;
}

Updated Pen

关于html - 悬停在使用位置 : absolute? 的按钮上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36812996/

相关文章:

javascript - 美国 map 拉斐尔插件自动更新和动态填充颜色

html - 按分辨率显示/隐藏不同数量的元素

jQuery .empty() && .append() 莫名其妙地失败了

java - 在java中寻找一个CSS解析器

javascript - 为什么 style.cursor 方法在 xPage 上不起作用?

javascript - 如何完成下面的JavaScript代码?

html - 如何在 CSS 中在更大的圆圈内制作圆圈,并在所有圆圈的中心制作文本?

html - 使 SVG 元素具有贪婪的高度

javascript - 一个html输入类型如何调用两个函数?

html - 为什么鼠标滚轮滚动在网站上停止工作,只有几次?