Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy do scrollbars appear when using a SVG element inside a DIV?
    primarykey
    data
    text
    <p>My aim is to have a <code>&lt;div&gt;</code> with a fixed size (dynamically set through JavaScript) that is only containing an <code>&lt;svg&gt;</code> element. When this <code>&lt;svg&gt;</code> is bigger than the parent <code>&lt;div&gt;</code> scrollbars should appear. When it's smaller, it's size should be set to those of the parent <code>&lt;div&gt;</code> - but no scrollbars should appear.</p> <p>This isn't working as expected as a little bit of code can show:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html;charset=utf-8"&gt; &lt;script type="text/javascript" src="lib/jquery-1.4.4.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="lib/jquery-ui-1.8.7.custom.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="lib/jquery.svg.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function() { $('#editor').svg(); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="editor" style="width:500px;height:500px;overflow:auto"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>This will create a nearly empty page, that contains a <code>&lt;div&gt;</code> with the fixed size of 500x500px - and a <code>&lt;svg width="500" height="500"&gt;</code> inside. This SVG has scrollbars - although they are not needed as the size would be a perfect fit.</p> <p>That this will only happen with a <code>&lt;svg&gt;</code> can be easily shown when the demo is modified to</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html;charset=utf-8"&gt; &lt;script type="text/javascript" src="lib/jquery-1.4.4.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="lib/jquery-ui-1.8.7.custom.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="lib/jquery.svg.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div style="width:500px;height:500px;overflow:auto"&gt;&lt;div style="width:500px;height:500px"&gt;&lt;/div&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>So now a <code>&lt;div&gt;</code> is inside of the parent <code>&lt;div&gt;</code> of exactly the same size - and the scrollbars are appearing.</p> <p>Can someone enlighten me, why the <code>&lt;div&gt;</code> and the <code>&lt;svg&gt;</code> are behaving differently?</p> <p>And how I can embed an SVG inside the parent <code>&lt;div&gt;</code> without appearing scrollbars when the size is the same (and with appearing ones when the size gets bigger?)</p> <p>Note: This is tested with Firefox and Chromium.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload