【问题标题】:Hover effect not working on positioned Anchor Tag <a>悬停效果不适用于定位的锚标记 <a>
【发布时间】:2017-04-06 10:14:30
【问题描述】:

当我将元素放置在图像上方时,悬停效果停止工作。 知道为什么吗?我正在学习。

我有一些定位元素,在 div 顶部具有不透明度的叠加层,背景图像位于固定位置。

编码整个部分和整个 CSS:

HTML:

<div class="wrapper"> <!-- Global Wrapper -->
<section>
    <div class="first-row">
       <div class="first-row__overlay">
       </div>
        <div class="jumbotron">
            <h2 class="jumbotron__header">This is the Title</h2>
            <p class="jumbotron__text">Lorem text
            </p>
            <div class="under-line"></div>
        </div>
        <a href="#" class="my-Btn">START NOW</a>
    </div>
</section>

CSS:

* {
  margin: 0;
  padding: 0;
  font-family: 'Arsenal', sans-serif;
  }
.wrapper {
  margin: 0;
  padding: 0;
  }
.first-row {
  width: 100%;
  height: 100vh;
  background: url("../images/paradise-1.jpg") no-repeat fixed center center;
  background-size: cover;
  text-align: center;
  position: relative;
  top: 0;
  left: 0;
  z-index: -100;
  }
.first-row__overlay {
  background-color: rgba(33, 46, 63, 1);
  width: 100%;
  height: 100vh;
  opacity: .35;
  position: relative;
  top: 0;
  left: 0;
  z-index: -99;
  }
.jumbotron { 
  width: 50%;
  margin: auto;
  color: white;
  position: relative;
  top: -70vh;
  z-index: 1;
  background-color: rgba(0, 0, 0, 0.3);
  }
.under-line {
  height: 10px;
  width: 0;
  margin: auto;
  background-color: transparent;
  border-bottom: 1px solid white;
  transition: 7s ease;
 }
.my-Btn {
 position: relative;
  top: -67vh;
  z-index: 99999999;
  color: #1d1e1f;
  font-weight: 300;
  font-size: 1.2em;
  padding: 10px 60px;
  background-color: #fdfdfe;
  border-radius: 30px;
  }
.my-Btn:hover {
  cursor: pointer;
  }

【问题讨论】:

  • 请分享您的整个代码。这会很有帮助。或者带有图片和锚链接的部分。
  • 我确实通过将锚标记的 html 代码放置在该部分之外来修复。但我仍然想知道为什么
    内部的悬停效果不起作用,当我尝试使用 jQuery 定位选择器时也不起作用

标签: css hover


【解决方案1】:

您将 z-index 设置为负位置 z-index: -100,将其从 .first-row 类中删除,它将解决问题。您需要密切关注 z-indexing,始终将元素视为彼此叠加的堆栈。

.first-row {
      width: 100%;
      height: 100vh;
      background: url("../images/paradise-1.jpg") no-repeat fixed center center;
      background-size: cover;
      text-align: center;
      position: relative;
      top: 0;
      left: 0;
}

【讨论】:

  • 是的,当然,只要我学会了如何投票,哈哈,我正在学习..让我看看。
  • 您可能还没有权限。
猜你喜欢
  • 2016-10-05
  • 2012-06-29
  • 2016-04-03
  • 1970-01-01
  • 2011-09-10
  • 2020-08-08
  • 1970-01-01
  • 1970-01-01
  • 2017-05-26
相关资源
最近更新 更多