width: 200px, padding: 10px, border: 5px solid, and margin: 20px, what is the total width the box occupies horizontally in the normal flow (content + padding + border + margin)?The total width is calculated as content width + left and right padding + left and right border + left and right margin.
So: 200 + (10*2) + (5*2) + (20*2) = 200 + 20 + 10 + 40 = 270px.
width: 300px, padding: 15px, border: 10px solid, and box-sizing: border-box, what is the actual width of the content area inside the box?With box-sizing: border-box, the width includes content, padding, and border.
The total width is fixed at 300px including padding and border.
Content width = total width - (padding left + padding right) - (border left + border right) = 300 - 30 - 20 = 250px.
margin-top: 20px and margin-bottom: 30px. When stacked vertically, what is the vertical space between them due to margin collapsing?When vertical margins collapse, the space between boxes is the larger of the two adjacent margins.
Between the bottom margin of the first box (30px) and the top margin of the second box (20px), the larger is 30px.
background-clip property controls where the background is painted.background-clip: padding-box; restricts the background color to the content and padding areas, excluding the border area.
padding: 1rem and border: 2px solid transparent. On focus, the border changes to 2px solid blue. Why is this approach better for accessibility than adding an outline?Changing border color on focus provides a visible focus indicator without causing layout shifts, which can confuse users.
Outlines can sometimes cause layout shifts or be inconsistent across browsers.