Inheritance
In CSS, child elements inherit from their parent element, even when the parent element is not the containing block. An element only inherits properties if the element itself does not define that property.
In the example below, you can see that the <body>
element has the font property set. All elements within the body will now use the font Georgia, unless something else is specified. And guess what! <h1>
has something else specified, so within the <h1>
element, Helvetica will be the chosen font.
What will the color of the intro element be?
HTML
CSS
That is correct, as intro has specified it's own color
property, that rule will be chosen (because it's more specific).
Last updated
Was this helpful?