Pavel Grinfeld Pavel Grinfeld - 1 year ago 91
HTML Question

Why does 100% equal 150 pixels?

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

<table class="root" cellspacing="0">
<svg class="root-symbol" viewBox="0 0 5 6.5" preserveAspectRatio="none" style="height:100%;background-color:lightgreen;">
<text x="0" y="6.5" font-size="9px">a</text>
<td><span style="font-size:2em;background-color:lightblue">I would expect it to be as tall as this span</span></td>

Answer Source

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.