Files
30-seconds-of-code/snippets/box-sizing-reset.md
Angelos Chalaris 7e69307433 Update tags, expertise and descriptions across
Fix anything that was a bit out of place
2020-03-05 22:52:51 +02:00

828 B

title, tags
title tags
Box-sizing reset layout,beginner

Resets the box-model so that widths and heights are not affected by their borders or padding.

<div class="box">border-box</div>
<div class="box content-box">content-box</div>
html {
  box-sizing: border-box;
}

*,
*::before,
*::after {
  box-sizing: inherit;
}

.box {
  display: inline-block;
  width: 150px;
  height: 150px;
  padding: 10px;
  background: tomato;
  color: white;
  border: 10px solid red;
}

.content-box {
  box-sizing: content-box;
}

Explanation

  1. box-sizing: border-box makes the addition of padding or borders not affect an element's width or height.
  2. box-sizing: inherit makes an element respect its parent's box-sizing rule.

Browser support