Is there a way how to apply z-index on a SVG path?
I have simple SVG arrow:
<svg class="arrow">
<path class="line" />
<path class="endpoint"/>
</svg>
If I use css to chnge z-index of the whole .arrow
everything works fine, but when I try to apply it only on .endpoint
it doesn't work.
Is there some solution or workaround for this?
Thank you very much.
Contrary to the rules in CSS 2.1, the z-index property applies to all SVG elements regardless of the value of the position property, with one exception: as for boxes in CSS 2.1, outer 'svg' elements must be positioned for z-index to apply to them.
One of the most common forms of interaction on a computer is clicking and dragging. I use it a lot for interactive demos, such as those in my SVG tutorial, and have a built a library for making simple draggable SVG diagrams.
The HTML <svg> element is a container for SVG graphics. SVG has several methods for drawing paths, boxes, circles, text, and graphic images.
If you use the svg. js library, you can use the ". front()" command to move any element to the top.
As an alternative, you can use "< use >"
Example:
<svg>
<circle id="shape1" cx="20" cy="50" r="40" fill="yellow" />
<rect id="shape2" x="4" y="20" width="200" height="50" fill="grey" />
<circle id="shape3" cx="70" cy="70" r="50" fill="blue" />
<use id="use" xlink:href="#shape2" />
</svg>
The shape2 layer will be the top most layer.
There's no z-index in SVG, it uses painters model. You'd have to remove the path from the DOM and re-add it before any elements that should be on top of it and after any elements that it should be on top of.
As you've discovered z-index only works on the complete <svg>
content as the html renderer controls how that is positioned before handing off to the SVG renderer to draw the internal SVG contents.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With