svg 图像内自定义区域中的链接不起作用

问题描述 投票:0回答:2

我想在 svg 图像内创建一些链接和悬停效果。因此,我在在线图像编辑器中的一个 svg 图像内创建了一些自定义透明区域,以便做到这一点。但是,当我尝试在这些自定义区域中应用一些链接时,如下所示,它不起作用。我怎样才能让它发挥作用?

<body>
  <svg>
      <defs></defs>
      <!-- custom ellipse which the link does not work -->
      <a href="some-link.com">
          <ellipse />  
      </a>

      <!-- normal path from the svg image, which the link work -->
      <a href="some-link.com">
          <path></path>
      </a>

      <!--rest of the image with many paths-->
      <path></path>
  </svg>
</body>
html css svg
2个回答
0
投票

ellipse
元素似乎无效。由于标记有错误,它甚至可能会影响父元素的功能。

自闭合标签末尾应有斜杠(因为 SVG 基于更严格的 XML),如下所示:

<ellipse />

此更改是否解决了链接问题?


0
投票

CSS 可用于覆盖 SVG 中的默认光标样式。这对我的情况有帮助。

svg {
  cursor: default;
}

svg a {
  cursor: pointer !important;
}
© www.soinside.com 2019 - 2024. All rights reserved.