There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
I just started this section, but from what I understand the old box model if an element is declared width of 200px with a padding of 20px and a border of 1px, the total width of the p1 box becomes 242px.
If you change the box-sizing to border-box, and the width is defined as 200px with the same values for padding and border, as mentioned above, the box size would remain at 200px. That means the content size decreases in order to maintain overall box width to 200px.
I think it’s useful, considering you are able to work with whole clear numbers, instead of having to fiddle around with something that is 242px wide compared to 200px wide.
I could be wrong, if I am i’d love to know that I am. From reading and looking at the diagram for border-box box model, that was the conclusion I came to.
Is margin used with Box Model: Border-Box? If so, is it configured outside of the border/specified width as with the Content-Box, and is it collapsing?
Border-box should set the Width an Height for all the Html elements to fixed , but when writing something like this code below where the padding exceeds a certain value (in this case it starts from 100px) it starts to modify the real width and height of the elements.
" The code in the example above resets the box model to border-box for all HTML elements. This new box model avoids the dimensional issues that exist in the former box model you learned about.
In this box model, the height and width of the box will remain fixed. The border thickness and padding will be included inside of the box, which means the overall dimensions of the box do not change."
I thought the height and width were fixed in the default box-model, and that the border thickenss and padding being included inside of the box, was also part of the defaul box-model.
Essentially, I do not understand the difference between the content-box and border-box, and I would highly appreciate assistance with this.
@mtf How do I apply box-sizing: border-box without having to use the universal selector? I like the idea of not having to load all HTMLElements in memory
One way is to select all the container elements you wish to apply the rule to, assuming your layout is not too complex. The memory issue referred to earlier is apparently less of a concern with today’s modern browsers so we needn’t panic about using the universal selector. Suggest read up on pros and cons to see if there are still any provisos.
In the example the height is set at 200px and the width is set at 300px. How come the border-box width is set at the height value of 200px and not the width value of 300px?
I was also confused but I think you are referring to the instructions and the diagram shown as an example on the right. I believe in this case we need to keep in mind that the theory provided with the code example does not reflect the result with the image shown on the right.