应用悬停效果后,无法单击图像链接

时间:2018-11-14 14:55:21

标签: html css

我正在遵循为图像添加悬停效果以轻松在其上显示一些文本的指南。问题是我的图像也可以用作链接,并且在应用CSS后它们无法单击。无论如何,我可以让它们再次单击吗?

ngOnInit() {
  this._userService.getter().subcribe(user => this.user = user);
}
.container {
    position: relative;
    width: 200px;
    height: 200px;
    display: inline-block;
}

.image {
    display: block;
    width: 200px;
    height: 200px;
}

.overlay {
    position: absolute;
    transition: all .3s ease;
    opacity: 0;
    background-color: #eee;
}

.container:hover .overlay{
    opacity: 1;
}

.text {
    color: white;
    font-family: sans-serif;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    font-size: 20px;
}

.overlayFade {
    height: 100%;
    width: 100%;
    top: 0;
    left: 0;
    background-color: #00b1bab3;
}

.container:hover .overlayLeft{
    width: 100%;
}

1 个答案:

答案 0 :(得分:2)

是的,您可以在.overlay规则中添加pointer-events: none;

.container {
  position: relative;
  width: 200px;
  height: 200px;
  display: inline-block;
}

.image {
  display: block;
  width: 200px;
  height: 200px;
}

.overlay {
  position: absolute;
  transition: all .3s ease;
  opacity: 0;
  background-color: #eee;
  pointer-events: none;
}

.container:hover .overlay {
  opacity: 1;
}

.text {
  color: white;
  font-family: sans-serif;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 20px;
}

.overlayFade {
  height: 100%;
  width: 100%;
  top: 0;
  left: 0;
  background-color: #00b1bab3;
}

.container:hover .overlayLeft {
  width: 100%;
}
<div class="container">
  <a href="/carportSpidsTag.jsp"><img src="./IMAGES/fladtTag.png" class="image"></a>
  <div class="overlay overlayFade">
    <div class="text">Fade</div>
  </div>
</div>