To tackle the issue at hand, it has been emphasized by others that deducting the padding value from the width of elements is crucial due to the impact of the box model. The calculation for element sizing within user agents takes padding into account.
With CSS3 introducing the box-sizing
attribute, you can override the default box model rendering and specify that the padding should be included within the element itself, fully respecting the set width and height:
/*Property without vendor prefixes*/
box-sizing:border-box;
For further insight, refer to this article:
You can also consult the specification for more details:
border-box
The specified width and height (along with min/max properties) of the element define its border box. This means any padding or border specified on the element will be contained within the specified width and height. The content's actual width and height are determined by subtracting the border and padding widths from the declared 'width' and 'height' properties. Since content dimensions cannot be negative ([CSS21], section 10.2), calculations are rounded down to 0.