CodeLab
Tutorials For Everyone
Run
<!Doctype HTML> <html> <head> <title>CSS Padding With Element Width and Box Sizing</title> <style> .div1{ padding: 20px; width: 200px; background: #555; color: #fff; box-sizing: border-box; } .div2{ padding: 0; width: 200px; background: #3949ab; color: #fff; } </style> </head> <body> <h2>CSS Padding With Element Width and Box Sizing</h2> Box-sizing property contained the content of the element to the width specified. Hence the width of both the elements remained similar. <div class="div1"> This div element has width of 200px with 20px padding. </div> <div class="div2"> This div element has width of 200px with 0px padding. </div> </body> </html>