How to scale SVG image to fill browser window?

后端 未结 1 1619
难免孤独
难免孤独 2020-11-27 11:26

This seems like it ought to be easy, but I\'m just not getting something.

I want to make an HTML page containing a single SVG image that automatically scales to fit

相关标签:
1条回答
  • 2020-11-27 12:04

    How about:

    html, body { margin:0; padding:0; overflow:hidden }
    svg { position:fixed; top:0; bottom:0; left:0; right:0 }
    

    Or:

    html, body { margin:0; padding:0; overflow:hidden }
    svg { position:fixed; top:0; left:0; height:100%; width:100% }
    

    I have an example on my site using (roughly) this technique, albeit with 5% padding all around, and using position:absolute instead of position:fixed:
    http://phrogz.net/svg/svg_in_xhtml5.xhtml

    (Using position:fixed prevents a very edge-case scenario of linking to a sub-page anchor on the page, and overflow:hidden can ensure that no scroll bars ever appear (in case you have extra content.)

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