CSS Tip: Preventing Div Expansion When Adding Padding
css box-sizingpadding overflowborder-boxdiv layoutcss cross-browser
Published·Modified·
To solve the issue of a div being stretched when padding is added, apply the box-sizing: border-box property. This ensures that padding and borders are included within the element's total width and height.
-moz-box-sizing: border-box; /* Firefox 3.5+ */
-webkit-box-sizing: border-box; /* Safari 3.2+ */
-o-box-sizing: border-box; /* Opera 9.6 */
-ms-box-sizing: border-box; /* IE 8 */
box-sizing: border-box;
Original source: CSS Tip: Preventing Div Expansion When Adding Padding. All rights reserved by the original author. If there is any infringement, please contact QQ: 337003006 for deletion.