图中和重叠段落中的可点击图像

Clickable image within figure and overlaid paragraphs

我无法让我的图片可点击。我有一个 <figure> 包裹在图像和一些段落元素上。我还有一些 CSS 这样,当您将鼠标悬停在图形上时,段落一次从底部(屏幕外)过渡到顶部。我认为这个动画是阻止我使用将图像包装在锚标记中的传统方法的原因,就像这个问题一样:a href link on img.

不幸的是,我已经在这个特定的 HTML 配置上进行了很多尝试,所以我不确定是否可以从根本上重新排列 DOM 元素。 如果可能的话我想保留数字、图像和段落的当前配置并解决这个问题。这是一个演示:

figure img {
  width: 300px;
  height: 300px;
}

figure h2 {
  max-width: 235px;
}

figure {
  border: 2px solid black;
  margin-bottom: 0;
  margin-top: -2px;
  margin-right: -40px;
  position: relative;
  z-index: 1;
  display: inline-block;
  overflow: hidden;
  text-align: center;
}

figure figcaption {
  padding: 2em;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

figure figcaption::before,
figure figcaption::after {
  pointer-events: none;
}

figure figcaption {
  position: absolute;
  top: 0px;
  left: 0;
  width: 100%;
  height: 100%;
}

figure p {
  font-family: Play;
  font-size: 20px;
  max-width: 235px;
  height: auto;
  overflow: hidden;
  position: relative;
  opacity: 0;
  bottom: -110%;
}

figure:hover h2 {
  opacity: 0;
  -webkit-transition: opacity 0.95s, -webkit-transform 0.95s;
  transition: opacity 0.95s, transform 0.95s;
}

figcaption:hover p:nth-of-type(1) {
  transition: 1s;
  bottom: 70%;
  opacity: 1;
}

figcaption:hover p:nth-of-type(2) {
  bottom: 70%;
  opacity: 1;
  transition: 1s;
  transition-delay: .3s;
}

figcaption:hover p:nth-of-type(3) {
  bottom: 70%;
  opacity: 1;
  transition: 1s;
  transition-delay: .6s;
}

figure:hover .border-rect {
  opacity: 0;
  -webkit-transition: opacity 0.5s;
  transition: opacity 0.5s;
}

figure.effect img {
  -webkit-transition: opacity 0.35s;
  transition: opacity 0.35s;
}

figure.effect:hover img {
  opacity: 0.4;
}

figure.effect figcaption::before,
figure.effect figcaption::after {
  position: absolute;
  top: 30px;
  right: 30px;
  bottom: 30px;
  left: 30px;
  content: '';
  opacity: 0;
  -webkit-transition: opacity 0.35s, -webkit-transform 0.35s;
  transition: opacity 0.35s, transform 0.35s;
}

figure.effect figcaption::before {
  border-top: 1px solid #fff;
  border-bottom: 1px solid #fff;
  -webkit-transform: scale(0, 1);
  transform: scale(0, 1);
}

figure.effect figcaption::after {
  border-right: 1px solid #fff;
  border-left: 1px solid #fff;
  -webkit-transform: scale(1, 0);
  transform: scale(1, 0);
}

figure.effect h2 {
  opacity: 1;
  -webkit-transition: opacity 0.95s, -webkit-transform 0.95s;
  transition: opacity 0.95s, transform 0.95s;
  -webkit-transition: -webkit-transform 0.35s;
  transition: transform 0.35s;
  -webkit-transform: translate3d(0, -20px, 0);
  transform: translate3d(0, -20px, 0);
  padding-top: 30%;
  max-width:235px;
}

figure.effect:hover figcaption::before,
figure.effect:hover figcaption::after {
  opacity: 1;
  -webkit-transform: scale(1);
  transform: scale(1);
}

figure:hover h2 {
  opacity: 0;
  -webkit-transition: opacity 0.5s;
  transition: opacity 0.5s;
}
    <figure class="effect">
      <img src="http://en.wikipedia.org/wiki/Mountain#/media/File:Lewis_overthrust_fault_nh10f.jpg">
      <figcaption>
        <a href="www.the-image-url.com/">
        <h2>Hover Somewhere Around Here
        </h2>
        <p>paragraph paragraph paragraph paragraph paragraph paragraph </p>
        <p>So you think you can hover, huh?</p>
        <p>paragraph paragraph paragraph paragraph paragraph paragraph paragraph paragraph paragraph paragraph</p>
        </a>
      </figcaption>
    </figure>

问题

我不太明白为什么我无法让图像变得可点击。我也试过将整个图形包裹在 <a> 中,但它不起作用。我的目标是:如果用户点击图中的任何地方,link 将被称为 我不想牺牲任何其他元素,因为它们目前处于状态。这是可能吗?如果是这样怎么办?

我的猜测是我的元素的分层或 z-index 不允许这样做,但我希望有解决办法。

您的图片标签被悬停的覆盖覆盖,您已将 link 给图片,这就是问题所在。您可以在叠加元素

中包含 link
<figure class="effect">

      <img src="http://en.wikipedia.org/wiki/Mountain#/media/File:Lewis_overthrust_fault_nh10f.jpg">

      <figcaption>
      <a href="www.the-image-url.com/">
        <h2>Hover Somewhere Around Here
        </h2>
        <p>paragraph paragraph paragraph paragraph paragraph paragraph </p>
        <p>So you think you can hover, huh?</p>
        <p>paragraph paragraph paragraph paragraph paragraph paragraph paragraph paragraph paragraph paragraph</p>
        </a>
        <a href="#">View more</a>
      </figcaption>
    </figure>

编辑:添加/更新关注CSS

figcaption a {
    top: 0px;
    left: 0;
    width: 100%;
    height: 100%;
    text-decoration: none;
    max-width: 300px;
    color: #333;
    position: absolute;
    right: 0px;
    text-align: center;
}
figure.effect h2 {
    opacity: 1;
    -webkit-transition: opacity 0.95s, -webkit-transform 0.95s;
    transition: opacity 0.95s, transform 0.95s;
    -webkit-transition: -webkit-transform 0.35s;
    transition: transform 0.35s;
    -webkit-transform: translate3d(0, -20px, 0);
    transform: translate3d(0, -20px, 0);
    padding-top: 30%;
    max-width: 235px;
    margin: auto;
}
figure p {
    font-family: Play;
    font-size: 20px;
    max-width: 235px;
    height: auto;
    overflow: hidden;
    position: relative;
    opacity: 0;
    bottom: -110%;
    margin: auto;
}