Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firefox doesn't respect font-size in SVG text

Tags:

css

firefox

svg

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): enter image description here

Here is what Firefox renders: enter image description here

I can't find what I am doing wrong. Any ideas? Thanks.

like image 672
Artefact2 Avatar asked Apr 26 '15 14:04

Artefact2


People also ask

Can you use font size on SVG?

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>

How do I change font size in SVG?

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.

How do I make SVG bold?

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."

What is font size adjust?

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.


1 Answers

You likely have a minimum font size set. This is a known bug, hopefully we'll fix it someday.

Unset it like this.

Minimum font size

like image 88
Robert Longson Avatar answered Nov 15 '22 08:11

Robert Longson