I'm trying to set the width and height attributes of SVG elements using CSS instead of putting them inline but I can't seem to get it working in firefox.
When I set the width/height inline on the element it displays with no problems.
<rect x="10px" y="50px" fill="green" width="20px" height="20px" />
When I try to set the width/height using CSS it works in Chrome but not in Firefox.
.box {
width: 20px;
height: 20px;
}
<rect class="box" x="50px" y="50px" fill="green" />
JSFiddle examples
Not all SVG element attributes can be styled with CSS. Only the ones designated as "properties" can be. See the list below from the SVG specification.
https://www.w3.org/TR/SVG/propidx.html
The (in development) SVG 2 specification will allow all attributes to be styled with CSS. And some browsers are starting to support that. But for now you won't be able to do it.
Update: Not all attributes will be styleable in SVG2. The list of styleable presentation attributes is here.
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