Note that there are some explanatory texts on larger screens.

plurals
  1. POPadding not coming as expected
    text
    copied!<p>I have a doubt why div size increase unexpectedly when padding is given. I am developing an HTML keeping aspect ratio.</p> <p>This is my HTML:</p> <pre><code>&lt;body&gt; &lt;div id="container" class="containerOuter"&gt; &lt;div class="main_container"&gt; &lt;div class="top"&gt; &lt;div class="top_inside"&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="bottom"&gt; &lt;div class="bottom_inside"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; </code></pre> <p>CSS:</p> <pre><code>html{ width:100%; height:100%; } body{ width:100%; height:100%; padding:0; margin:0; } .containerOuter { background-color:silver; } .main_container{ width:100%; height:100%; } .top{ width:96%; height:76%; padding:2%; background:#F00; } .bottom{ width:96%; height:16%; padding:2%; background:#0F0; } .top_inside{ width:100%; height:100%; background:#60C; } .bottom_inside{ width:100%; height:100%; background:#C0C; } </code></pre> <p>JS:</p> <pre><code>(function( $ ) { $.fn.keepRatio = function() { var $this = $(this); var ratio = 1.333333333; function ReSize() { var nw = $(window).height() * ratio; $this.css('width', nw + 'px'); $this.css('height', $(window).height() + 'px'); } $(window).resize(ReSize); ReSize(); } })( jQuery ); $(document).ready(function(){ $('#container').keepRatio(); }); </code></pre> <p>when border-box is used the size is reduced</p> <pre><code>div { -webkit-box-sizing:border-box; /* Safari/Chrome, other WebKit */ -moz-box-sizing:border-box; /* Firefox, other Gecko */ box-sizing:border-box; /* Opera/IE 8+ */ } </code></pre> <p>Can somebody explain this unexpected behavior ? Thanks in advance</p>
 

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