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

时间:2015-03-26 20:03:04

标签: html css hyperlink hover

我已经尝试过使用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;
}

2 个答案:

答案 0 :(得分:1)

绝对定位的孩子坐在锚链接的顶部,因此任何指针交互都会失败。

你可以在那个允许事件通过的孩子身上使用pointer-events:none,但浏览器支持它不是很好。

&#13;
&#13;
* {
  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;
}
&#13;
<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>
&#13;
&#13;
&#13;

您最好将div包含在链接中,并按照评论中的建议重新计算代码。

答案 1 :(得分:1)

您可以将整个可扩展的div包装在锚标记中,这样您就可以确保可挖掘的div是可点击的,并且它指向图像引用的链接。

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;
}