I have, in my SVG, a foreignObject which contains a p element. I want the height of this structure to be adapted to the height of my text.
The p element is already adapted : I've done nothing for that.
But I have troubles for the foreignObject. If I remove the field height, it doesn't work. height:auto doesn't work either.
Since there is no real use of scaling up and down the
foreignObject
itself, then you can set both foreignObjectheight
andwidth
to1
, and via CSS setforeignObject { overflow: visible; }
to make its content visible whatever it is and do whatever you need to do it with it.You can set height of the
foreignObject
element inem
units, maybe that could help?Right now the
width
andheight
attributes of aforeignObject
are required, and must have values > 0, otherwise the element will not be rendered.Update: An alternative is to just set the dimensions of the foreignObject to 100%, and use the fact that the foreignObject has a transparent background per default. Since other elements in svg are laid out in an absolute manner anyway they don't depend on the foreignObject size.