简体   繁体   English

路径中的 SVG 图像 - HTML

[英]SVG Image in Path - HTML

I've got a tricky issue going on that I can't seem to figure out.我有一个棘手的问题,我似乎无法弄清楚。 It's a lot of different files so let's start without any code or file docs added.它有很多不同的文件,所以让我们开始时不添加任何代码或文件文档。

So I've got a SVG image with a lot of square paths all over it.所以我有一个 SVG 图像,上面有很多方形路径。 I placed an Square image over one of the square paths in Inkscape.我在 Inkscape 中的一个方形路径上放置了一个方形图像。 Then I embedded the SVG file into HTML, where I think added a link to that path w/ image.然后我将 SVG 文件嵌入到 HTML 中,我认为在其中添加了一个指向该路径的链接(带有图像)。 I was having no issues adding the links or anything and it was working just fine, but now it seems as if the image is canceling out the link.我在添加链接或任何内容时没有遇到任何问题,并且工作正常,但现在似乎图像取消了链接。 Before the link worked just fine but when the image loads over the square it acts as if it's covering the link.在链接工作正常之前,但是当图像加载到方块上时,它就像覆盖了链接一样。 Before the image is fully loaded into the browser the link works and is accessible.在图像完全加载到浏览器中之前,该链接有效并可访问。 But once the image loads on top of that path with the link it covers it and doesn't work anymore.但是一旦图像加载到带有链接的路径之上,它就会覆盖它并且不再起作用。

Is this common and am I dumb?这很常见吗,我傻吗? Seems like I'm just missing something here.好像我只是在这里遗漏了一些东西。 Need to basically add the image somehow without it covering the linked path underneath.需要以某种方式基本上添加图像而不覆盖下面的链接路径。

Please help!!!请帮忙!!!

You have probably already found the answer.您可能已经找到了答案。 In SVG all elements are drawn on top of all previous (so the order of the elements in the file matters).在 SVG 中,所有元素都绘制在所有之前的元素之上(因此文件中元素的顺序很重要)。

If one element completely covers the other below him then it will essentially block its interactive events.如果一个元素完全覆盖了他下面的另一个元素,那么它基本上会阻止其交互事件。 The solution is to notify CSS engine to drop through any pointer events for this element (or elements with same style) using解决方案是使用以下命令通知 CSS 引擎删除此元素(或具有相同样式的元素)的任何指针事件

.nopointer { pointer-events: none }

in the section of the SVG or in the wrapped HTML CSS style section.在 SVG 部分或在包装的 HTML CSS 样式部分中。

For the links to work for SVG elements - since you can add a link attribute to SVG elements as well, eg if you would have SVG IMAGE elements overlaid on your rectangles - don't forget to add the XLink namespace in the SVG root element declaration.对于适用于 SVG 元素的链接 - 因为您也可以向 SVG 元素添加链接属性,例如,如果您将 SVG IMAGE 元素覆盖在矩形上 - 不要忘记在 SVG 根元素声明中添加 XLink 命名空间.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM