I am running into an issue where Firefox doesn't seem to apply the font-size
property (set in CSS) to SVG text
elements.
The example below is enough to reproduce the issue on Firefox:
<svg width="40em" height="25em" viewBox="0 0 40 25">
<style type="text/css"><![CDATA[
text { font-size: 1px; }
text.foo { font-size: 2px; }
]]></style>
<text x="0" y="10" class="foo">Hello, world! foo</text>
<text x="0" y="20">Hello, world! bar</text>
</svg>
Here is the expected result (Chromium):
Here is what Firefox renders:
I can't find what I am doing wrong. Any ideas? Thanks.
Note: As a presentation attribute, font-size can be used as a CSS property. See the css font-size property for more information. You can use this attribute with the following SVG elements: <altGlyph>
You can not change the font size or font width because SVG is not a font. It is Scalable Vector Graphics. If you would have some text in your SVG then you could do something with the font from the text element.
To make text bold with SVG, set the weight of the font with font-weight="bold". The font-weight can also be set to 100, 200, ... 900 with higher values corresponding to a greater "boldness."
The font-size-adjust property gives you better control of the font size when the first selected font is not available. When a font is not available, the browser uses the second specified font. This could result in a big change for the font size. To prevent this, use the font-size-adjust property.
You likely have a minimum font size set. This is a known bug, hopefully we'll fix it someday.
Unset it like this.
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