topskill.dev
CoursesTracks
0
All courses/CSSInheritance and the cascade
CSS Foundations
9 / 10
← CSS
○CSS Rule Style an Exhibit Card○Write Your First CSS Rule○CSS Selectors Target Exhibit Details○Target Exhibit Details○Apply CSS Three Sources○Apply CSS Three Ways○Specificity Resolve a Style Conflict○Resolve Specificity●Inheritance and the cascade✦Module Quiz
○Color Palette○Color Palette○Background Layer○Background Layer○Type Rhythm○Type Rhythm○Borders and Shadows○Borders and Shadows✦Module Quiz
○Box Model Seed Packet Card○Space a Seed Packet○Display Swap Table Labels○Arrange Swap Table Labels○Positioning Pickup Pin○Pin the Pickup Location○Sizing and Overflow○Size a Seed-Swap Notice○Sticky scroll headings✦Module Quiz
○Advanced Selectors Book Cart Sign○Target a Book Cart Sign○Pseudo-Classes Night Cart States○Style Night Cart States○Pseudo-Elements○Add a Book-Quote Mark✦Module Quiz
○Lantern Market navigation○Lantern Market navigation✦Module Quiz
○Community garden request card○Community garden request card✦Module Quiz
○Flex Direction○Flex Direction○Main-Axis Spacing○Main-Axis Spacing○Cross-Axis Alignment○Cross-Axis Alignment○Wrapping and Flex Items○Wrapping and Flex Items○Flexbox Navigation○Flexbox Navigation✦Module Quiz
○Grid Tracks○Grid Tracks○Grid Gaps○Grid Gaps○Grid Placement○Grid Placement○Responsive Grid○Responsive Grid✦Module Quiz
○River radio schedule○Harbor radio schedule✦Module Quiz
○Field note color system○Field note color system○Transforms○Rotate a Field Note○Resilient styles✦Module Quiz
○Kite festival signal○Garden festival signal✦Module Quiz
○Garden forecast○Harbor forecast○Fluid sizing○Fluid weather bulletin○Images that fit✦Module Quiz
○Seed inventory table○Tool checkout table✦Module Quiz
○Community maker profile○Maker profile sheet✦Module Quiz

Inheritance and the cascade

Let a notice share its text styles

Specificity compares rules that target the same element. Inheritance answers a different question: if an element has no winning declaration for an inherited property, which value reaches it from its parent?

The supplied notice has a heading, paragraph, emphasized phrase, and button. Color and font properties normally inherit. Padding, margin, and borders do not. A child without its own color uses its parent’s computed color; it does not compete with the parent’s selector specificity. Even a simple color rule directly on the child takes precedence over an inherited color.

css
.panel { color: navy; }
.panel em { color: inherit; }

Here inherit explicitly asks the emphasized text to use its parent’s color. initial instead asks for the property’s initial value; unset inherits for an inherited property and otherwise uses its initial value. They are not interchangeable reset words. The notice’s button has a supplied font of its own. font: inherit resets its font shorthand to the parent’s font settings, without removing native button semantics or its default focus indication. It is a visual placeholder, not a working visit-times service.

Before specificity

The browser has built-in user-agent styles, visitors can supply user styles, and page CSS is author styling. Inline, internal, and external CSS are all author sources, not three different origins. For ordinary declarations, author styles outrank normal user and browser styles. A normal inline declaration outranks normal author stylesheet declarations on that element.

!important comes after a value, before the semicolon: color: navy !important. It changes cascade priority, not selector specificity. Important author declarations beat normal author declarations, but important user and browser declarations have higher priority still. Do not reach for it whenever a rule loses: inspect which declaration wins first. Layers, animations, and transitions add further cascade rules; the simple specificity comparisons in this module deliberately exclude them.

For selectors in the same ordinary priority, compare ID count first, then classes/attributes/pseudo-classes, then elements/pseudo-elements. A selector with one ID beats many classes; this is a comparison of columns, not a base-ten score. Combinators and * add no weight. If those comparisons tie, source order decides in our unlayered examples.

Your Task

  1. Set .notice to color: #174a3a so its heading and ordinary paragraph inherit the shared green.
  2. Set .notice strong to color: inherit so the emphasized phrase stops overriding that shared color.
  3. Set .notice button to font: inherit so the native button uses the notice’s family and size.

Edit the marked rules in style.css. Run after each change, then Submit. Inspect a child paragraph in your browser’s Elements panel: Styles shows matched declarations; Computed shows the resulting value. A crossed-out declaration lost a conflict. A missing declaration may mean the selector did not match, the property/value was invalid, or a condition did not apply. Check those possibilities before making a selector more specific.

The next module uses these shared text styles to build a readable color palette.

Take the Quiz →
Files
  • ⋄index.html
  • ⋄style.css
Loading editor…