After reading several stack posts about WHY you might want to use an <img>
or <object>
tag to reference a svg file, I've yet to find one that answers a specific question i have with regards to CSS and svg <path>
tags. If you embed the svg into the js or html, you can manage all hover events for example, in the CSS rules
A CSS rule like so if i wanted to have a hover effect on a svg map of buildings.
path[id^="building"]:hover {
opacity: 0.5;
}
But if the svg file is very large (200kb), full of path vectors, and you want instead reverence the svg instead (see below samples), then you will break the above CSS rule. All paths with id beginning with "building" will stop showing the hover effect of .5 opacity.
<object type="image/svg+xml" data="http://localhost:49031/my.svg" `width="300" height="300"></object>`'
Or
<img id="map" src="http://localhost:49031/my.svg"></img>
I cant seem to wrap my head around a way to access the paths inside a reference svg file. I've started reading on <use>
and <g>
svg tags, but i have not come across the missing link that pulls this all together for me.
IMPORTANT NOTE: I realize you can specify <style>
tags inside each svg, but i would rather not manage my code this way if there is a better option, which I'm sure there is. These svgs will be used as a svg map, with clickable hotspots that trigger maps in and out of view so individual buildings, or rooms on a floor plan can be selected, and write the objects id to a form field.