Challenge: Apply Box Sizing to Elements
Task
Let's explore the practical differences between the content-box and border-box values for the box-sizing property. Your task is as follows:
- Apply the
content-boxvalue to thebox-sizingproperty for the element with thecontent-boxid. - Apply the
border-boxvalue to thebox-sizingproperty for the element with theborder-boxid.
index.html
index.css
box-sizing: content-box: Width and height exclude padding and border.box-sizing: border-box: Width and height include padding and border.
index.html
index.css
Explanation
In this example, we have two div elements, each utilizing a different value for the box-sizing property:
- The first
divfeatures a red border and employs the default value ofcontent-boxfor thebox-sizingproperty. Despite setting thewidthandheightto200px, thepaddingandbordercontribute additional space, resulting in dimensions larger than200pxin both directions; - Conversely, the second
divshowcases a blue border and opts forborder-boxas thebox-sizingproperty value. While thewidthandheightremain at200px, thepaddingandborderare included within the box's dimensions.
We can observe the contrasting sizes of the two boxes, with the first being larger due to the additional space from padding and border. In contrast, the second box maintains a consistent size of 200px, inclusive of padding and border.
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 2.56
Challenge: Apply Box Sizing to Elements
Swipe to show menu
Task
Let's explore the practical differences between the content-box and border-box values for the box-sizing property. Your task is as follows:
- Apply the
content-boxvalue to thebox-sizingproperty for the element with thecontent-boxid. - Apply the
border-boxvalue to thebox-sizingproperty for the element with theborder-boxid.
index.html
index.css
box-sizing: content-box: Width and height exclude padding and border.box-sizing: border-box: Width and height include padding and border.
index.html
index.css
Explanation
In this example, we have two div elements, each utilizing a different value for the box-sizing property:
- The first
divfeatures a red border and employs the default value ofcontent-boxfor thebox-sizingproperty. Despite setting thewidthandheightto200px, thepaddingandbordercontribute additional space, resulting in dimensions larger than200pxin both directions; - Conversely, the second
divshowcases a blue border and opts forborder-boxas thebox-sizingproperty value. While thewidthandheightremain at200px, thepaddingandborderare included within the box's dimensions.
We can observe the contrasting sizes of the two boxes, with the first being larger due to the additional space from padding and border. In contrast, the second box maintains a consistent size of 200px, inclusive of padding and border.
Thanks for your feedback!