Why does 100% equal 150 pixels?

后端 未结 2 1866
小蘑菇
小蘑菇 2021-01-17 05:22

The following code results in a table that 150 pixels tall. Why 150? Is this an SVG quirk or something more general?

https://jsfiddle.net/cc9tyw5v/31/



        
相关标签:
2条回答
  • 2021-01-17 06:02

    The span you are attempting to fit the height of is not the parent of the SVG. It is a sibling, and therefore height:100% will not fit its height.

    0 讨论(0)
  • 2021-01-17 06:10

    According to this source

    SVG isn't (just) an image. SVG is a document. The default size for HTML replaced elements will be used: 300px wide, 150px tall. This applies for <img>, <object> or <iframe>. The default 300x150 size also applies to inline <svg> elements within HTML documents, but that's a relatively recent consensus from the HTML5 specifications: other browsers will by default expand inline SVG to the full size of the viewport—equivalent to width: 100vw; height: 100vh; — which is the default size for SVG files that are opened directly in their own browser tab. Internet Explorer cuts the difference, using width of 100% and height of 150px for images and inline SVG.

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