The site now fits every screen. The rest of the course is about the newer CSS that helps keep it tidy, and how to use it safely, starting with a row that should stand out by itself.
Plot 19 is free this season. The starter’s plots page already says so. Its Tended by cell holds the same <span class="badge-free">Free</span> as plot 12’s. Yet only plot 12’s row stands out, because its highlight hangs on a class="free" that someone added to the <tr> by hand. Nobody remembered to add one for plot 19.
In this lesson, you’ll style that row by what it contains, so the highlight follows the badge. On the way, you’ll shorten selector lists that repeat themselves and work out how specific the new selectors are. Start with the repetition, which is already in your stylesheet.
Shorten a Selector List With :is()
A selector list repeats whatever its selectors share. In the components layer of garden-practice/style.css, the nav’s hover rule names .site-nav a twice:
.site-nav a:hover,
.site-nav a:focus-visible {
background-color: var(--stripe);
color: var(--text);
}
The :is() pseudo-class takes a selector list in its parentheses and selects any element that matches one of those selectors. If you’ve ever tested whether a value is one of several options, it’s the same idea, written inside a selector. Replace the rule’s two selectors with one:
.site-nav a:is(:hover, :focus-visible) {
background-color: var(--stripe);
color: var(--text);
}
Save, then hover over a nav link and tab to another. Both still get the pale green shading, so the page looks exactly as it did.
The cascade doesn’t change either. :is() takes the specificity of its most specific argument. :hover and :focus-visible are both pseudo-classes, so the new selector scores (0, 2, 1), the same as each selector it replaced.
That rule matters once the arguments differ. Take a rule for the links in the nav and the footer:
:is(.site-nav, footer) a {
color: var(--green);
}