Set X and Y value for g element of SVG

前端 未结 1 1765
孤街浪徒
孤街浪徒 2021-01-12 15:22

I am relatively new in SVG drawing with HTML5.

What I want to do is to make a group of elements in SVG with g element so that all e

1条回答
  •  温柔的废话
    2021-01-12 15:45

    elements don't support x or y attributes. You can use a transform instead though.

    I've decreased the values from 1000 to 100 as otherwise the output is outside the 500 x 300 canvas of the outer element.

    I've provided additional x and y attributes on the text element so it appears positioned as in your example. If wanted you could put the text itself in a element or an element.

    
      
        SVG Title Demo example
        
        My Text
      
    

    or using an additional element to avoid x and y on the text itself.

    
      
        SVG Title Demo example
        
        
            My Text
        
      
    

    Alternatively you could use an inner element instead of a element as that does support x and y attributes

    
      
        SVG Title Demo example
        
        My Text
      
    

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