Learn HTML and CSS: Inheritance
Inheritance
Frank gave the whole card a colour, and to his surprise all the text inside changed with it. Except the link. "Why won't that link listen?"
What a child inherits
Some properties are passed on by an element to everything inside it: its children inherit them. That goes for text: color, font-family, font-size, font-weight, line-height and text-align.
That's why body { font-family: … } is enough for the whole page, and .play { color: … } colours all the text in the card.
Other properties don't inherit, like background-color and width: otherwise every child would get its own background and width. In the cascade under the page you can see where the date gets its colour from.
.play { color: #2a6f4e;}A rule of its own comes first
Inheritance only fills in what's still empty. If an element has a rule of its own for a property, however simple, that rule beats anything it would inherit.
Links always have such a colour of their own: from the browser, and here from basis.css. If you want a link to take its parent's colour after all, write color: inherit: "take your parent's value".
.play { color: #2a6f4e;}.play p a { color: inherit;}Try it yourself
Make all the text in the cards green (#2a6f4e), the link in the text included. The buttons stay white, and the rest of the page stays as it is.
/* Your CSS goes here. */<!DOCTYPE html><html lang="en"> <head> <title>Curtain Up drama club</title> <link rel="stylesheet" href="basis.css"> <link rel="stylesheet" href="style.css"> </head> <body> <header> <h1>Curtain Up</h1> <p class="slogan">Drama club in Grantham since 1952</p> <nav id="menu"> <ul> <li><a href="index.html">Home</a></li> <li class="active"><a href="playbill.html">Playbill</a></li> <li><a href="join.html">Join us</a></li> <li><a href="contact.html">Contact</a></li> </ul> </nav> </header> <main> <section id="playbill"> <h2>On the playbill</h2> <article class="play"> <h3>The Miser</h3> <p class="date">14 to 16 March</p> <p>A farce after <a href="https://en.wikipedia.org/wiki/Molière">Molière</a>, about a man who loves his money more than his children.</p> <blockquote> <p>I haven't laughed this much in years.</p> </blockquote> <a class="button" href="https://tickets.curtainup.example/miser">Tickets</a> </article> <article class="play"> <h3>Murder at the Rectory</h3> <p class="date">9 to 11 May</p> <p>Everyone has an alibi, except the cat.</p> <a class="button" href="https://tickets.curtainup.example/rectory">Tickets</a> </article> </section> <section id="dates"> <h2>Performances</h2> <table> <tr> <th>Day</th> <th>Time</th> </tr> <tr> <td>Friday 14 March</td> <td>8 pm</td> </tr> <tr> <td>Saturday 15 March</td> <td>8 pm</td> </tr> <tr> <td>Sunday 16 March</td> <td>3 pm</td> </tr> </table> </section> <section id="downloads"> <h2>To read</h2> <ul> <li><a href="programme.pdf">The programme</a></li> <li><a href="rules.pdf">The club rules</a></li> <li><a href="https://en.wikipedia.org/wiki/The_Miser">About The Miser</a></li> <li><a href="mailto:boxoffice@curtainup.example">Email the box office</a></li> </ul> </section> </main> <footer> <p>The Crown Hall, 21 Church Street, Grantham</p> </footer> </body></html>body { margin: 0; font-family: system-ui, sans-serif; background: #fbf6ee; color: #2b1d1d;}header { padding: 20px 16px 14px; background: #5c1515; color: #f5e6c8;}header h1 { margin: 0;}.slogan { margin: 4px 0 12px;}#menu ul { display: flex; flex-wrap: wrap; gap: 4px 18px; margin: 0; padding: 0; list-style: none;}#menu a { color: #f5e6c8;}main { padding: 8px 16px 24px;}h2 { color: #7a1c1c;}a { color: #7a1c1c;}.play { margin: 12px 0; padding: 12px 16px; border-radius: 16px; background: #ffffff;}.play h3 { margin: 0 0 4px;}blockquote { margin: 8px 0; padding-left: 12px; border-left: 3px solid #d4a017;}.button { display: inline-block; padding: 6px 16px; border-radius: 999px; background-color: #7a1c1c; color: #ffffff; text-decoration: none;}table { border-collapse: collapse;}th,td { padding: 6px 10px; border: 1px solid #e6d3c3; text-align: left;}footer { padding: 12px 16px; background: #5c1515; color: #f5e6c8;}Ready for more?
The full lesson has 5 exercises, from easy to challenging, with hints, points and a streak you can build.
Start the lesson