2

I would an svg element which could scale to fit its children elements. Say you have:

<svg> 
  <rect width=10 height=1000/>
<svg>

It seems like there would be a way to get the svg to scale to fit the rectangle inside of it.

Unfortunately, it appears such a thing is impossible, at least according to this:

SVG Fill Width to Child Elements

Can anyone give me an explanation as to why this cannot be acheived? It seems like this would be a highly requested feature... or maybe I'm just not getting something.

Thanks!

tnrich
  • 8,006
  • 8
  • 38
  • 59

1 Answers1

1

A special viewBox value of "auto" has been discussed for inclusion in the specification for SVG 2, which is still under development.

If it makes the final specification, this would do what you are suggesting.

Paul LeBeau
  • 97,474
  • 9
  • 154
  • 181
  • Interesting, thanks for the info. So, just to double check, the proposed viewBox: "auto" would allow the svg container to grow to fit its contents? – tnrich Apr 14 '15 at 06:21
  • Yes. It would be set to the union of the bounding boxes of all the child elements. – Paul LeBeau Apr 14 '15 at 06:37