Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Ask DevTools Why a Rule Fails

In this lesson, you found out why four rules on the work day notice you built in HTML did nothing. For each one, you selected the element, read the Styles pane, tried the fix in DevTools, and copied it into the file.

Follow Along

Rosa asked Kofi, one of the volunteers, for four changes to the work day notice: the title centered, the job descriptions not bold, the family-friendly job in italics, and its heading in the garden’s green. Kofi added these four rules at the end of events/events.css, after the .family-friendly rule from Rank Inline Styles and !important. Add them to the end of your own file to follow along:

Language: CSS Filename: events/events.css
h1 {
  justify-content: center;
}

p {
  font-weight: normal;
}

.family-friendly {
  font-style: itallic;
}

h2.family-friendly {
  color: oklch(0.447 0.116 152.7);
}

He saved, and nothing on the notice changed. CSS fails silently, so instead of guessing, select the element and ask four questions, in order.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 You know how the cascade picks a value. In this video, you’ll ask DevTools why a rule doesn’t apply. Rosa asked Kofi, one of the volunteers, for four changes to the work day notice.

00:13 She wanted the title centered, the job descriptions not bold, the family-friendly job in italics, and its heading in the garden’s green. At the end of events.css, Kofi added four rules.

00:25 He saved, and nothing on the notice changed. His rules are below the video, to follow along. CSS fails silently, so instead of guessing, select the element and ask four questions, in order.

00:42 First, is the rule listed? Select the mulch heading. The Styles pane lists every rule that matches it, and Kofi’s heading rule isn’t there.

00:52 Other rules from events.css are here, so the file loaded, and the filter’s empty. Compare the selector with the element. Kofi’s rule wants an h2 with the family-friendly class.

01:04 In the Elements panel, the heading has only an id. The class is on the paragraph below it, and the heading belongs to the same job, so give it the class too.

01:12 Save, and Kofi’s rule is listed. One catch: a rule for a state, like hover, is listed only while the element is in that state. Force the state with the :hov button.

01:27 Second, is there a warning icon? Select the mulch job. Kofi’s value is crossed out, with a warning icon. Hover it, and Chrome says invalid property value. Kofi typed it with a double L.

01:40 The browser dropped it silently.

01:43 Try the fix in the pane. Click the value, type italic, and press Enter. The mulch job turns italic, and so does its heading, which is in the family-friendly group now.

01:55 That edit lives only in this tab. The asterisk before events.css says DevTools changed its own copy, and a reload brings the typo back. So copy the fix into the file, and save.

02:10 Third, is it crossed out with no icon? Select the compost job. Kofi’s font-weight is crossed out with no icon: it’s valid, and it lost. The winner is higher in the pane, however late Kofi’s rule sits in the file.

02:24 It’s the rule that bolds the paragraph after each heading.

02:29 The Computed pane names the winner wherever it is. Filter for font-weight, and expand the row. The winner comes first, with Kofi’s under it.

02:39 A crossed-out line isn’t always a mistake. The paragraph’s grey is crossed out too, because the job rule’s green beat it, as it should. To confirm the winner, untick its checkbox.

02:51 Both job descriptions lose their bold. But that rule also bolds the events page’s dates, so make Kofi’s selector more specific. Change it to the job class.

03:01 Zero, one, zero beats zero, zero, two. Save, and after the reload, that rule is back on and loses to the job class. Fourth, is there an info icon? Select the title.

03:16 Kofi’s justify-content is greyed out, with an info icon after it. It’s valid, and nothing beat it, but it does nothing here. Hover the icon, and DevTools says why.

03:26 It only works in a flex or grid container.

03:30 You’ll meet those when you lay out pages, and that’s all you need about them for now. The property that centers a heading’s text is text-align. Change it in the file, save, and the title moves to the center.

03:44 When a rule doesn’t apply, select the element and work down the list. Not listed: check the filter and that the file loaded, then the selector. A warning icon: it’s invalid.

03:55 Crossed out, no icon: it lost, and the Computed pane names the winner. An info icon: no effect here. Try the fix in DevTools, then copy it into your file.

04:08 All four of Rosa’s changes now show. Next is the lesson Store Colors in Custom Properties, where you’ll keep the garden’s colors in one place.

Become a Member to join the conversation.