Is it possible to nest text (like a text
element) inside an SVG path
element?
I am asking because I would like a text balloon to show up when hovering over a path, something like this:
path#mypath:hover text {
display:block;
}
I would like to avoid using JavaScript, but I understand that may be the only option.
Yes you can use
<text>
inside<svg>
.You can use:
To apply css rules when hovered. Here is working JSFiddle. But if you want to display a bubble notification that changes position based on hovered element, you must use JavaScript. If the position does not change then you can do it in CSS by simply hiding and displaying a div.
If you want to display tooltip, You can insert title element into target shape element, like this.
According to this: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/path your can not nest
<text>
inside<path>
You could however use an adjacent element as the trigger for the hover effect: http://jsfiddle.net/93ufH/1/
CSS