Aligning the objects in SVG center

前端 未结 3 1877
情话喂你
情话喂你 2021-01-21 04:09

How can i align objects within svg tag center. I can make it aligned by adjusting the x,y cordiantes in viewbox. But every time i need to change the value according to the size

3条回答
  •  耶瑟儿~
    2021-01-21 05:10

    You can move the min-x and min-y coordinates to place your content in the center. Description of the viewBox can be found here: https://sarasoueidan.com/blog/svg-coordinate-systems/

    The better way to go about it is to export the file with the correct bounding box to get it completely center aligned. Opened your svg (in Sketch) added an invisible box around it of 35 x 35px, it exported to whole thing and cleaned it up:

    svg {
      border: 1px solid red;
    }
    
      
    

提交回复
热议问题