Css Fundamentals: Inheritance
Css Fundamentals: Inheritance
Inheritance
IN A ROCKET
Learn front-end development at rocket speed
INHERITANCE
Some properties on a selector are inherited by all the children of that selector.
Hello world!
p
HTML CSS
<body> main { color: green; }
<main>
Here starts the main area of this site.
<article>
<p>We hope you enjoy this article.</p>
</article>
</main>
</body>
Browser
Web page title
index.html
border-collapse
font-family
list-style-image
visibility
border-spacing
font-size
list-style-position
white-space
caption-side
font-style
list-style-type
widows
color
font-variant
list-style word-break
cursor
font-weight
word-spacing
direction
font-size-adjust
orphans
empty-cells font-stretch
quotes
font
tab-size
letter-spacing
text-align
line-height text-align-last
text-decoration-color
text-indent
text-justify
text-shadow
text-transform
HTML CSS
<body> h2 { color: blue; }
<h2>A normal header</h2>
<header> header { color: green; }
<h2>I should be blue but I'm inheriting
header h2 { color: inherit; }
green</h2>
</header>
</body>
Browser
Web page title
index.html
A normal header
I should be blue but I'm inheriting green
HTML CSS
<body> main { color: green; }
<main> p { color: initial; }
<h1>Here starts the main area<h1>
<article>
<p>We hope you enjoy this article.</p>
</article>
</main>
</body>
Browser
Web page title
index.html
HTML CSS
<body> main {
<main> color: green;
Here starts the main area of this site. font-size: 200%;
<article> }
<p>We hope you enjoy this article.</p>
</article> p { all: initial; }
</main>
</body>
Browser
Web page title
index.html
HTML CSS
<body> p { color: blue; }
<p>All paragraphs are blue.</p>
header { color: red; }
<header>
<p>My parent is red but I'm a paragraph.</p>
</header> main { color: green; }
<main> main p { color: unset; }
<p>I should be blue but I'm resetting to my
parent's color.</p>
</main>
</body>
Browser
Web page title
index.html
HTML CSS
<body> p { color: blue; }
<p>All paragraphs are blue.</p>
header { color: red; }
<header>
<p>My parent is red but I'm a paragraph.</p>
</header> main { /* No color */ }
<main> main p { color: unset; }
<p>I don't inherit any color from my parent so I
just reset to initial.</p>
</main>
</body>
Browser
Web page title
index.html
inarocket .com
Learn front-end development at rocket speed
+ READY TO USE CODE
+ QUIZZES
+ FREE UPDATES
by miguelsanchez.com
inarocket .com
Learn front-end development at rocket speed
Inheritance
IN A ROCKET
Learn front-end development at rocket speed