最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to resize a svg to fit inside a div? - Stack Overflow

programmeradmin2浏览0评论

on trying fitting in to div(with border) svg is cut off from the right size.

PEN

HTML

 <div style="position:relative;width:550px;height: 500px;background: gainsboro;border: 4px solid;">

 <-- My SVG -->

 </div>

help me fit this svg in 550x500

on trying fitting in to div(with border) svg is cut off from the right size.

PEN

HTML

 <div style="position:relative;width:550px;height: 500px;background: gainsboro;border: 4px solid;">

 <-- My SVG -->

 </div>

help me fit this svg in 550x500

Share Improve this question edited Jul 8, 2016 at 9:52 elreeda 4,5972 gold badges21 silver badges45 bronze badges asked Jul 8, 2016 at 9:51 user3698196user3698196 931 silver badge8 bronze badges 1
  • 1 The viewBox of svg should be in aspect ratio of 550X550. – Mr_Green Commented Jul 8, 2016 at 9:55
Add a ment  | 

1 Answer 1

Reset to default 8

Don't use width or height in your SVG.

Use viewbox instead. Then the SVG will scale automatically (mostly).

<svg xmlns="http://www.w3/2000/svg" viewbox ="0 0 959 593">

Codepen Demo

发布评论

评论列表(0)

  1. 暂无评论