Q1
Why does setting width: 100%; padding: 20px cause horizontal scrollbar overflow without box-sizing: border-box?
Under default content-box, width: 100% sizes only the inner content box—padding and borders get added *on top* (100% + 40px), overflowing the viewport. box-sizing: border-box keeps total width locked to 100%.
Q2
Why does z-index: 9999 still fail to bring a dropdown above a sibling card sometimes?
z-index only competes inside its nearest Stacking Context. Parents with transform, opacity < 1, filter, or position: relative; z-index: 1 trap child layers inside their own local stacking context.
Q3
What causes margin collapsing between two vertical block siblings—and how do Flex/Grid containers change it?
Adjacent vertical margins in normal block flow collapse to max(m1, m2) instead of adding. Flex and Grid items establish new formatting contexts where vertical margins do NOT collapse.
Q4
Why does position: sticky; top: 0 silently fail when an ancestor has overflow: hidden?
Sticky positioning binds relative to the nearest scrolling ancestor. Setting overflow: hidden (instead of overflow: clip) creates a scroll box that locks sticky travel inside that container.
Q5
What is the key layout difference between flex: 1 (flex: 1 1 0%) and flex-grow: 1 (flex: 1 1 auto)?
flex: 1 sets flex-basis: 0% so items divide free space equally regardless of text length, whereas flex-grow: 1 starts from auto content size first—making short buttons narrower than long-text buttons.
Q6
Why does <button> without an explicit type='button' unexpectedly reload pages inside <form>?
The HTML specification defaults <button> inside a <form> to type='submit'. Always specify type='button' on modal toggles, close icons, and non-submit controls.
Q7
How does repeat(auto-fit, minmax(260px, 1fr)) differ from auto-fill when a grid has only 2 items on a wide screen?
auto-fit collapses empty phantom tracks to 0px, stretching the 2 real items across the full row. auto-fill keeps the empty column tracks reserved, leaving whitespace on the right.
Q8
Why do margin-top or height have no effect on <span> (display: inline) elements?
Inline boxes ignore vertical margin-top/margin-bottom and explicit width/height. Switch to inline-block, flex, or block when vertical sizing is needed.
Q9
Why is prefers-reduced-motion media query important in modern UI engineering?
It respects OS accessibility settings for users with vestibular disorders by disabling or softening heavy parallax/slide animations automatically in CSS.
Q10
Why should hero images set explicit width and height attributes alongside CSS height: auto?
HTML width/height lets browsers compute the aspect ratio before the image downloads, reserving exact vertical space and preventing Cumulative Layout Shift (CLS) penalties in Core Web Vitals.