【问题标题】:My links stop working when the box hover is applied应用框悬停时,我的链接停止工作
【发布时间】:2015-05-31 00:28:01
【问题描述】:

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

【问题讨论】:

  • 你能发布正确的 HTML sn-p 吗???
  • position:absolutefloat:left 不兼容...选择其中一个,
  • 我们无法想象您指的是什么“盲区”图片,请澄清
  • 这里有一些随机图像jsfiddle.net/2x3c8coz,但我不确定你要做什么
  • 您是否试图使可悬停的 div 可点击到图像指向的链接?如果是这种情况,您可以将整个可悬停的 div 包装在锚标记中。

标签: html css hyperlink hover


【解决方案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;
}

【讨论】:

    【解决方案2】:

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

    您可以在那个孩子上使用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 包含在链接中并按照 cmets 中的建议重构您的代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多