SVG rect not showing up in firefox but works on chrome
Asked Answered
A

2

6

I am drawing a simple two rectangle svg as follows:

<svg  width="72px" height="72px" viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg">
          <rect stroke-dashoffset="0" x="2.4px" y="2.4px"></rect>
          <rect ng-class="$ctrl.expiryClass"
          x="2.4px" y="2.4px"
          stroke-dasharray={{$ctrl.dashlength}}
          stroke-dashoffset={{$ctrl.offset}}></rect>
      </svg>

This works well in chrome and looks like this:

Progress bar as svg rect

However, the svg is not showing up in FireFox and I am only seeing the purple 2h box. Any idea whats going on?

Appleby answered 18/8, 2017 at 22:14 Comment(2)
There some questions about the stroke-dashoffset not workin in firefox, like this one #18298982Favata
The rect has no width and height attributes.Yardage
E
11

I expect you are setting the rectangle's width and height using CSS. Correct?

If so, that's an SVG 2 thing that currently only works in Chrome. You'll need to use regular width and height attributes if you want this to be cross-browser compatible.

<rect stroke-dashoffset="0" x="2.4px" y="2.4px" width="100px" height="100px"/>
Elitism answered 19/8, 2017 at 6:38 Comment(1)
Firefox implemented this some years ago now.Yardage
S
-1

As @paul mentioned its a problem with rect()

You can easily convert an SVG rect to a path with inkscape.

Open the .svg in inskape, click on layers, select all rects, convert them to path (cmd shift C). Then go to Object/Transform... and click on apply. Save the file.

Submit answered 26/6 at 1:33 Comment(3)
It was a problem. It's was fixed a long time ago.Yardage
@RobertLongson wdym? I encountered this issue the other day. Rect() doesn't seem to support width/height using cssSubmit
did you forget to use units? Feel free to ask another question with your test case.Yardage

© 2022 - 2024 — McMap. All rights reserved.