anderspitman
anderspitman

Reputation: 10520

Nested g vs svg

I'm building out some responsive SVG-based components (based around Backbone views). The convention I'm using is that when a component is created, it is provided with a DOM element to render itself into. When rendering, the component checks the size of the DOM element and fills the entire available space.

I was using g elements, but they don't have their own width and height; they just match their contents. So I made a hack where I would append a rect that was the size I needed. This works pretty well, but it is hacky.

Today I discovered that svg elements can be nested just like g, but they're also able to have their own width and height. I just tested it out and it seems to work great. Are there any downsides I'm missing creating a bunch of nested svg elements like this?

Upvotes: 1

Views: 834

Answers (1)

Paul LeBeau
Paul LeBeau

Reputation: 101830

No. There shouldn't be any downsides to using nested <svg> elements. But your description of what you are doing is rather vague, so I can't guarantee that you won't strike any in your particular use case.

Upvotes: 1

Related Questions