本文介绍了SVG中的ForeignObject的自动高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的SVG中,我有一个ForeignObject,其中包含一个p元素.我希望此结构的高度适合于我的文字的高度.

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.

p元素已经适应:我对此没有做任何事情.

The p element is already adapted : I've done nothing for that.

但是我对foreignObject有麻烦.如果我删除了场高,它将不起作用. height:auto也不起作用.

But I have troubles for the foreignObject. If I remove the field height, it doesn't work. height:auto doesn't work either.

推荐答案

由于实际上并没有实际使用foreignObject上下缩放,因此可以将foreignObject heightwidth都设置为,并通过CSS设置foreignObject { overflow: visible; }使它的内容可见,无论做什么,并做任何需要使用它的操作.

Since there is no real use of scaling up and down the foreignObject itself, then you can set both foreignObject height and width to 1, and via CSS set foreignObject { overflow: visible; } to make its content visible whatever it is and do whatever you need to do it with it.

这篇关于SVG中的ForeignObject的自动高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 22:15