Learn HTML and CSS: The cascade
The cascade
Frank has two rules for the buttons: a green one and a red one. The buttons are red. "Why that one, and not the other?" The browser doesn't pick at random: it follows a fixed order, the cascade.
The last one wins
When two rules say something different about the same property of the same element, and their selectors weigh the same, the last one wins.
Within a file that's the rule further down. Between files it's the file linked later: style.css comes after basis.css, and that's why your CSS beats the drama club's.
In the cascade under the page you'll see the winner at the top and the loser crossed out, with the reason.
.button { background-color: #2a6f4e;}.button { background-color: #b8860b;}Where a rule comes from
The browser has a stylesheet too: that's why an <h3> is bold, a link underlined and an <li> an item with a bullet.
Every rule of the site beats it, however simple. With h3 { font-weight: normal; } the title is no longer bold.
And above the site's stylesheets there's the style attribute, as you saw in module 2. From weak to strong: the browser, the stylesheets, the style attribute.
h3 { font-weight: normal;}Try it yourself
Frank once made the headings gold. Now he wants them green (#2a6f4e), and the titles of the plays (h3) no longer bold.
h2 { color: #b8860b;}<!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