Answer the question
In order to leave comments, you need to log in
How to properly embed SVG and/or SVGZ with a stylesheet?
There is a style file:
.my-style{
fill:red;
stroke:black;
stroke-width:2;
}
<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 50 50" style="enable-background:new 0 0 50 50;" xml:space="preserve" display="none">
<defs>
<symbol id="circle" viewBox="0 0 50 50">
<circle class="my-style" stroke-miterlimit="10" cx="25" cy="25" r="24"/>
</symbol>
<symbol id="rect" viewBox="0 0 50 50">
<rect fill="red" stroke="black" stroke-width="2" stroke-miterlimit="10" width="48" height="48"/>
</symbol>
</defs>
</svg>
<svg><use xlink:href="#circle"></use></svg>
<svg><use xlink:href="#rect"></use></svg>
<svg><use xlink:href="mysite/files/svg#circle"></use></svg>
<svg><use xlink:href="mysite/files/svg#rect"></use></svg>
Answer the question
In order to leave comments, you need to log in
Quite right , Lev Solntsev explained: "This is how use works"
In more detail, as soon as we apply the command
useeverything inside falls into the shadow DOM and external styles do not work, but there are ways to get around these restrictions.
circle rect{
fill:inherit;
stroke:inherit;
}
#circle{
fill:red;
stroke:black;
stroke-width:1px;
}
#rect{
fill:yellowgreen;
stroke:black;
stroke-width:1px;
}
circle rect{
fill:inherit;
stroke:inherit;
}
#rect:hover {
fill:red;
stroke-width:3px;
}
#circle:hover{
fill: yellowgreen;
stroke-width:3px;
}
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="css/svg.css" ?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
width="120" height="55" viewBox="0 0 120 55" >
<defs>
<symbol id="circle" >
<circle cx="25" cy="27" r="24"/>
</symbol>
<symbol id="rect" >
<rect x="60" y="2" width="48" height="48"/>
</symbol>
</defs>
<use xlink:href="#circle"></use>
<use xlink:href="#rect"></use>
</svg>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question