I am working on a project where some SVG tags are auto-generated based on the user provided input. For instance the most common scenario I have is that I may have many SVG objects (i.e. rect, ellipse, polygon, etc.) inside a <svg>
container.
Now the issue is that my container SVG has a certain length and width regardless of its contents. I am trying to make my container SVG tag to only have so much length and width so that it can contain its content but no blank space.
For example: in this fiddle the SVG with id=svg1
is much larger than its contents need it to be.
How can i make the SVG container of appropriate size?
Note: I don't know which shapes are going to be put inside the SVG container and where they are going to be placed. Also, the SVG can contain another <svg>
tag inside it and shapes can be inside this inner SVG.
Note 2: In some cases the width and height of the SVG container may be needed to be increased so as to not truncate the contents. Alos, it is imperative that i only use a pure HTML/CSS solution for certaion reasons.
` tag, i would either have to make a svg text element or make do with a badly designed page. Since the HTML is auto-generated, i don't have the flexibility to follow the first option.
– Surender Thakran Nov 27 '13 at 06:12