What is box-sizing: border-box in CSS?
By default (content-box) the width is only for the content, and padding and border are added on top. With box-sizing: border-box the width includes padding and border.
* { box-sizing: border-box; }
.box { width: 200px; padding: 20px; border: 5px solid #333; } /* total width 200px */
Most developers add this rule to every stylesheet. See CSS Box Model.
Learn more about the similar topics:
| Tutorials |
|---|
| CSS Borders |
| Rounded Corners in CSS |
| CSS Height and Width |
| CSS Padding |
| CSS Margins |
| CSS Box Model |
| CSS Outline |
| Exercises & Assignments |
|---|
| Write CSS to create a box with border, padding and rounded corners |
| Write CSS to create a circle and a pill-shaped button |
| Write CSS to style a login form |
| Interview Questions & Answers |
|---|
| What is the CSS box model? |
| What is the difference between margin and padding in CSS? |
| What is box-sizing: border-box in CSS? |