How can I resize an SVG?

后端 未结 1 469
面向向阳花
面向向阳花 2020-12-31 14:01

I have code like this:

  
     

        
相关标签:
1条回答
  • 2020-12-31 14:25

    The width and height attributes on the SVG element only define the size of the drawing area. They don't scale the contents to fit that area. For that, you need to also use the viewBox attribute, like so:

    <svg viewBox="0 0 32 32" height="100" width="100" ...>
    

    The viewBox attribute establishes the coordinate system that is used for all the child elements of the SVG. You can then use the width and height to stretch this coordinate system to the desired size.

    You can use the preserveAspectRatio attribute to decide how to scale if the aspect ratios don't match.

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