anchor element not working when ::before pseudo element

徘徊边缘 提交于 2019-12-12 04:48:57

问题


I have applied some styles on the parent ::before and the anchor element inside doesn't work anymore.

It seems that something is overriding the default behavior of the anchor element but I can not figure out what.

How can I fix this?

.ugallery_item::before {
content: '';
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  transition:all 0.8s;
  opacity:0;
  background:url("http://placehold.it/14x14") #eabe24 no-repeat center center;
}
.ugallery_item:hover::before {
  opacity:0.8;
}
<div class="ugallery_item ugallery_item_image  shuffle-item filtered" style="position: absolute; width: 140px; top: 0px; left: 0px; opacity: 1;" rel="706" data-groups="[&quot;label_0&quot;]">
    <a class="ugallery_link ugallery_lightbox_link" href="http://placehold.it/300x400" title="">
      <img src="http://placehold.it/150x150" alt="" class="ugallery-image" style=" margin-left:0px;  margin-top:0px;width:140px; height:140px">
        <div class="ugallery_lb_text" rel="706"></div>

    </a>
</div>

回答1:


You've absolutely positioned the pseudo-element over the link..so naturally the mouse can't click on it.

You move the pseudo-element to the actual link instead.

.ugallery_item {
  position: absolute;
  width: 140px;
  top: 0px;
  left: 0px;
  opacity: 1;
}
.ugallery_lightbox_link {
  display: block;
  position: relative;
}
.ugallery_lightbox_link:before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  transition: all 0.8s;
  opacity: 0;
  background: url("http://placehold.it/14x14") #eabe24 no-repeat center center;
}
.ugallery_lightbox_link:before {
  opacity: 0.8;
}
<div class="ugallery_item ugallery_item_image  shuffle-item filtered" rel="706" data-groups="">
  <a class="ugallery_link ugallery_lightbox_link" href="http://placehold.it/300x400" title="">
    <img src="http://placehold.it/150x150" alt="" class="ugallery-image" style=" margin-left:0px;  margin-top:0px;width:140px; height:140px" />

    <div class="ugallery_lb_text" rel="706"></div>

  </a>

</div>



回答2:


You want it so you can click the a and have the opacity correct?

Why not just use the a-tag itself, and not the container?

.ugallery_item a::before {
content: "";
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  transition:all 0.8s;
  opacity:0;
  background:url("http://placehold.it/14x14") #eabe24 no-repeat center center;
}
.ugallery_item a:hover::before {
  opacity:0.8;
}

JSFiddle



来源:https://stackoverflow.com/questions/29032388/anchor-element-not-working-when-before-pseudo-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!