title: Prevent padding from causing element to overflow its parent
body: <p>Here is my HTML structure:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.parent{
    background-color:#f7f7f7;
    width: 100px;
    height: 100px;
    border:2px solid;
  }
  
  .child{
    height: 100%;
    width: 100%;
    background-color:#cf5;
    padding: 15px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="parent"&gt;
    &lt;div class="child"&gt;something&lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>As you see <code>div.child</code> goes out of <code>div.parent</code>. That's because of <code>padding: 15px;</code>. Well, how can I calculate this in CSS:</p>
  
  <pre><code>.child{
      height: (100% - the number of padding);
      width: (100% - the number of padding);
  }
  </code></pre>
  
  <p>So this is expected result: <em>(noted that there also should be <code>padding: 15px</code>)</em></p>
  
  <p><a href="https://i.stack.imgur.com/teySL.png" rel="noreferrer"><img src="https://i.stack.imgur.com/teySL.png" alt="enter image description here"></a></p>