Embed SVG in SVG?

前端 未结 6 575
無奈伤痛
無奈伤痛 2020-11-27 11:00

I have an SVG document, and I would like to include an external svg image within it, i.e. something like:



        
      
      
      
6条回答
  •  無奈伤痛
    2020-11-27 11:31

    It is worth mentioning that when you embed SVGs into another SVG with:

    
    

    then the embedded SVG takes a rectangular shape with given dimensions.

    That is to say, if your embedded SVG is a circle or some shape other than a square, then it becomes a square with transparency. Therefore, mouse events get trapped into that embeded square and do not reach the parent SVG. Watch out for that.

    A better approach is using a pattern. To fill a shape, either a circle, a square or even a path.

    
     
       
     
    
    

    Then use the pattern like this:

    
    

    Now your mouse events do not get stuck into transparent image squares!

提交回复
热议问题