应用框悬停时我的链接停止工作

My links stop working when the box hover is applied

我试过使用 z-index 来控制框悬停上的绝对和相对定位,但它不起作用。任何机构对为什么有任何建议?链接在那里,但位于图像的一侧,而不是正上方。

HTML

 <div id="container1">
     <a href="firstcoding.html"> <img src="images/blindsided1.jpg"> </a>
     <div class="textbox">
         <p id="title1">First Coding <br> Attempt</br></p>
         <p id="text1"> This brief was my first attempt at designing a website.</p>
      </div>
 </div>

CSS

a:hover {
    z-index: 99;
}
#container1 {
    position:absolute;
    float:left;
}
.textbox:hover {
    opacity:1;
}
#title1 {
    padding-top: 20px;
    text-align:center;
    color:#FFF;
    font-family:"bebas";
    font-size:32px;
    word-spacing:2px;
    letter-spacing:1px;
    text-decoration:underline;
}
#text1 {
    padding-top:40px;
    text-align:center;
    color:#FFF;
    font-family:"bebas";
    font-size:16px;
    word-spacing:2px;
    letter-spacing:1px;
}
.textbox {
    width:361px;
    height:362px;
    position:absolute;
    top:0;
    left:0;
    opacity:0;
    border-radius:300px;
    background-color: rgba(0, 0, 0, 0.75);
    -webkit-transition: all 0.7s ease;
    transition: all 0.7s ease;
}

绝对定位的 child 位于锚点 link 之上,因此任何指针交互都会失败。

您可以在 child 上使用 pointer-events:none,这将允许事件通过,但浏览器对它的支持不是很好。

* {
  margin: 0;
  padding: 0;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
a,
img {
  display: block;
}
#container1 {
  position: relative;
  border: 1px solid red;
  float: left;
}
#container1:hover .textbox {
  opacity: 1;
}
#title1 {
  padding-top: 20px;
  text-align: center;
  color: #FFF;
  font-family: "bebas";
  font-size: 32px;
  word-spacing: 2px;
  letter-spacing: 1px;
  text-decoration: underline;
}
#text1 {
  padding-top: 40px;
  text-align: center;
  color: #FFF;
  font-family: "bebas";
  font-size: 16px;
  word-spacing: 2px;
  letter-spacing: 1px;
}
.textbox {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0;
  border-radius: 50%;
  background-color: rgba(0, 0, 0, 0.75);
  -webkit-transition: all 0.7s ease;
  transition: all 0.7s ease;
  pointer-events: none;
}
<div id="container1">
  <a href="firstcoding.html">
    <img src="http://lorempixel.com/output/cats-h-c-361-362-10.jpg" />
  </a>

  <div class="textbox">
    <p id="title1">First Coding
      <br/>Attempt
    </p>
    <p id="text1">This brief was my first attempt at designing a website.</p>
  </div>

您最好按照评论中的建议将 div 包装在 link 和 re-factor 您的代码中。

您可以将整个 hoverable div 包裹在锚标记中,这样您就可以确保 hoverable div 是可点击的,并且它指向图像所在的 link正在引用。

HTML

<div id="container1"> 
    <a href="firstcoding.html"> 
        <img src="http://zoarchurch.co.uk/content/pages/uploaded_images/91.png"> 
        <div class="textbox">
            <p id="title1">First Coding
                <br>Attempt</br>
            </p>
            <p id="text1">
                This brief was my first attempt at designing a website.
            </p>
        </div>
    </a>
 </div>

CSS

a:hover {
    z-index: 99;
}
.textbox:hover {
    opacity:1;
}
#title1 {
    padding-top: 20px;
    text-align:center;
    color:#FFF;
    font-family:"bebas";
    font-size:32px;
    word-spacing:2px;
    letter-spacing:1px;
    text-decoration:underline;
}
#text1 {
    padding-top:40px;
    text-align:center;
    color:#FFF;
    font-family:"bebas";
    font-size:16px;
    word-spacing:2px;
    letter-spacing:1px;
}
.textbox {
    width:361px;
    height:362px;
    position:absolute;
    top:0;
    left:0;
    opacity:0;
    border-radius:300px;
    background-color: rgba(0, 0, 0, 0.75);
    -webkit-transition: all 0.7s ease;
    transition: all 0.7s ease;
}