How to append div tag into a SVG rect element?

后端 未结 1 1162
野的像风
野的像风 2021-01-25 06:50

I couldn\'t find a correct solution for this problem so I decided to write a new question.

I\'m not even sure that this is possible but I hope it is.

So here is

1条回答
  •  后悔当初
    2021-01-25 07:25

    Unfortunately, it's not possible: you cannot append an HTML element to an SVG element.

    The only way for using a div (or a p, h1, li etc) in an SVG is by using foreignObject. In your code, something like this:

    
    
        
            
                
                    
                    
                    
    		    
    TestContent

    Notice that foreignObject comes after the rectangle, not inside it (as in your code). Also, notice that foreignObject does not work in IE: https://developer.mozilla.org/en/docs/Web/SVG/Element/foreignObject

    0 讨论(0)
提交回复
热议问题