Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding padding to svg g element

my d3.js code generates the following HTML (this was taken from inspect element)

The paths render a circle with text at the bottom of it.

Ultimately I want the text to be UNDER the circle within the bounds of the SVG element. If the SVG element is larger, the G element renders larger. I need to control either the size of the G element or the size of the path elements.

How would I add width and height constraints or padding to the G element? It doesn't respond to width, height, x, y in style

cursory google search was not very helpful

thanks for any insight.

like image 386
CQM Avatar asked Feb 19 '13 14:02

CQM


People also ask

How do I use SVG padding?

There is no padding or margin, but you can set x and y attributes such that the elements inside or outside get a padding and margin. For example, if an element starts at (0,0), starting at (10, 10) will automatically give a margin of 10.

What is the G element in SVG?

The <g> SVG element is a container used to group other SVG elements. Transformations applied to the <g> element are performed on its child elements, and its attributes are inherited by its children. It can also group multiple elements to be referenced later with the <use> element.

Does padding make an element bigger?

If an element has a specified width, any padding added to that element will add to the total width of the element. This is often an undesirable result, as it requires that an element's width be recalculated each time the padding is adjusted.

What is the G element?

The <g> element is a container element for grouping together related graphics elements.


1 Answers

The <g> element doesn't really render at all, it's the <path> and <text> elements you need to adjust.

like image 115
robertc Avatar answered Oct 09 '22 15:10

robertc