使用 Clip-Path 自定义 Link 形状和动画

Custom Link Shape and Animation with Clip-Path

我最近一直在学习 CSS 中 clip-path 的神奇属性,但我 运行 在尝试创建自定义图像时遇到了问题 link。我无法让实际形状成为可点击的 link。

当我尝试将 <a> 放置在剪裁后的 div 中时,形状本身将不可点击 - 即使我将其设置为与其父级 div 相同的尺寸.这是我的 linkable 剪辑路径 (https://css-tricks.com/the-many-ways-to-link-up-shapes-and-images-with-html-and-css/) 的参考站点。

我想知道它是否不能成为 link 因为它在鼠标悬停时有动画?这是我的代码片段。

/* Styles the link */
#inner-link {
  width: 200px;
  height: 200px;
}

/* Styles the parent container */
#button-container {
  width: 200px;
  height: 200px;
  margin: 10%;
  background-color: #ed991c;
  clip-path: polygon(50% 0%, 100% 100%, 0% 100%, 0% 100%, 0% 100%, 0% 100%, 0% 100%);
}
#button-container:hover {
  animation: arrow 0.5s forwards;
}

/* animation from triangle to arrow */
@keyframes arrow {
  0% {
    clip-path: polygon(50% 0%, 100% 100%, 0% 100%, 0% 100%, 0% 100%, 0% 100%, 0% 100%);
    background-color: #ed991c;
  }
  100% {
    clip-path: polygon(30% 0%, 100% 50%, 30% 100%, 30% 75%, 0% 75%, 0% 25%, 30% 25%);
    background-color: #edd11c;
  }
}
  
  
<div id="button-container">
  <a id="inner-link" href="https://www.target.com/"><a>
 </div>

a标签是内联元素,内联元素没有高度和宽度。

快速解决方法是将 display: blockdisplay: inline-block 添加到您的 #inner-link

#inner-link {
    width: 200px;
    height: 200px;
    display: block;
}

#inner-link {
  width: 200px;
  height: 200px;
  display: block;
}


/* Styles the parent container */

#button-container {
  width: 200px;
  height: 200px;
  margin: 10%;
  background-color: #ed991c;
  clip-path: polygon( 50% 0%, 100% 100%, 0% 100%, 0% 100%, 0% 100%, 0% 100%, 0% 100%);
}

#button-container:hover {
  animation: arrow 0.5s forwards;
}


/* animation from triangle to arrow */

@keyframes arrow {
  0% {
    clip-path: polygon( 50% 0%, 100% 100%, 0% 100%, 0% 100%, 0% 100%, 0% 100%, 0% 100%);
    background-color: #ed991c;
  }
  100% {
    clip-path: polygon( 30% 0%, 100% 50%, 30% 100%, 30% 75%, 0% 75%, 0% 25%, 30% 25%);
    background-color: #edd11c;
  }
}
<div id="button-container">
  <a id="inner-link" href="https://www.target.com/"></a>
</div>