CSS Tutorial
Every HTML element has a box model consisting of four components:
box-sizing
property to the style declaration of any element.content-box
or border-box
based on your desired behavior./* content-box */
.element {
width: 100px;
padding: 10px;
border: 1px solid black;
box-sizing: content-box;
}
/* border-box */
.element2 {
width: 100px;
padding: 10px;
border: 1px solid black;
box-sizing: border-box;
}
In this example, element
will have a total width of 122px (100px content + 10px padding + 10px border on both sides), while element2
will have a total width of 100px (padding and border are included within the width).