How do CSS shorthand declarations reset other properties?
Quick answer
A CSS shorthand sets several related longhand properties at once. Any component you leave out is assigned that shorthand’s default value, so a later shorthand can replace a value you set earlier on one of its longhands. To debug, identify the shorthand, list the properties it affects, and check which earlier values its omitted components reset. [S1]
The question, the details, the next step.
A practical checklist
Find the longhand property whose value is unexpected.
Scan later declarations for shorthands that set that property.
Check the shorthand’s defaults for components it omits.
Decide whether the shorthand or a separate longhand should own the intended value.
Update the declarations, then inspect the applied styles in the browser.
A few more useful answers
Does a shorthand preserve earlier longhand values that it leaves out?
Not necessarily. Omitted components are assigned the shorthand’s default value, which can override an earlier longhand declaration. [S1]
Can a shorthand reset a related property that is not obvious from its written values?
Yes. The cited background example also sets background-attachment: scroll, and the font example includes additional resets such as font-variant: normal. [S1]
Does this example tell me which declaration wins across my entire stylesheet?
No. It explains the two declarations shown. Other applicable rules in your stylesheet may affect the final value, so inspect the styles applied to your element.
Sources
References used for this guide.
- [S1] Shorthand properties — CSS | MDN developer.mozilla.org · Checked
