![]() |
The box-sizing property in CSS tells us how to figure out the complete width and height of an element. It decides whether to include things like padding and borders in that calculation or not. Syntaxbox-sizing: content-box; Table of Content Using content-boxThe content box is the default setting for the box-sizing property. In this property, when you set the width and height of an element, those values only consider the content itself. Padding and borders are not counted within these dimensions. Use the box-sizing property to specify the box model. In this case, set it to content-box. This property ensures that the width specified in the next step includes only the content and not padding or border. Example: Illustration of Box-sizing property control the size of HTML elements using content-box. HTML
CSS
Output: Using border-boxIn the border-box property, when you set the width and height of an element, it includes the content, padding, and borders altogether. Use the box-sizing property to specify the box model. In this case, set it to border-box. Use width: 200px; to set the width of the element to 200 pixels. Example: Illustration of Box-sizing property control the size of HTML elements using border-box. HTML
CSS
Output: Using inheritThe inherit value allows an element to borrow the box-sizing preference from its parent. Use the box-sizing property in the .parent class to set the box model to border-box. This property ensures that the specified width includes both the content and padding but not the border. Example: Illustration of Box-sizing property control the size of HTML elements using inherit. HTML
CSS
Output: |
Reffered: https://www.geeksforgeeks.org
CSS |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |