Quizz

The full text of this chapter, to read or revisit. To practise, do the exercises.

β–Ά Do the exercises

Exercise 1 β€” CSS Selector Challenge: Basics

Which of the following is the correct CSS selector to target all paragraph elements on a page?

Options
β€’ p { }
β€’ #p { }
β€’ .p { }
β€’ <p> { }

Hint : Remember the basic syntax for element selectors in CSS. No special characters are needed to target all elements of a specific type.

Exercise 2 β€” Selector Specificity Battle

Given the following CSS rules and HTML element, which color will the text be?

p { color: black; } .text { color: blue; } #content { color: red; } p.text { color: green; }<p id="content" class="text">What color am I?</p>
Options
β€’ red
β€’ blue
β€’ green
β€’ black

Hint : Think about the specificity hierarchy of CSS selectors. Which selector has the highest specificity weight?

Exercise 3 β€” Complete the Selectors

Complete the CSS selectors to target the elements as described in the comments.

Hint : Remember the correct syntax for each type of selector - element selectors have no prefix, class selectors start with a dot, and ID selectors start with a hash/pound sign.

Exercise 4 β€” Match Selectors to Specificity Weight

Match each CSS selector with its correct specificity weight from lowest to highest.

Items to match
β€’ p
β€’ .highlight
β€’ p.highlight
β€’ #main-content
Definitions
β€’ Lowest specificity (element selector)
β€’ Medium specificity (class selector)
β€’ Higher specificity (element + class selector)
β€’ Highest specificity (ID selector)

Exercise 5 β€” Choosing the Right Selector

Which selector would be the MOST appropriate for styling a navigation menu that appears once at the top of every page on your website?

Options
β€’ #main-nav { }
β€’ nav.main-nav { }
β€’ div { }
β€’ body > div > div { }

Hint : Consider which selector provides the right balance of specificity and semantic meaning for a unique navigation component.

Exercise 6 β€” Specificity Basics

Which of the following selectors has the HIGHEST specificity?

Options
β€’ #header { }
β€’ h1 { }
β€’ .title { }
β€’ * { }

Hint : Think about which type of selector (element, class, or ID) has the highest specificity in CSS.

Exercise 7 β€” Selector Strength Comparison

Which of the following selectors has the WEAKEST effect in terms of specificity?

Options
β€’ h1 { }
β€’ #title { }
β€’ .heading { }
β€’ h1 { color: red !important; }

Hint : Think about the hierarchy of CSS selectors and which type has the least power when styles conflict.

Exercise 8 β€” Which Style Wins?

Given the following CSS rules, which one will determine the color of the text in the paragraph below?

p { color: black !important; } #content { color: red; } .text { color: blue; } body p.text { color: green; }<div id="content"> <p class="text">What color am I?</p> </div>
Options
β€’ black
β€’ red
β€’ blue
β€’ green

Hint : Pay close attention to all factors that affect specificity, including the special !important declaration which overrides normal specificity rules.

Exercise 9 β€” Match Scenarios to Selector Types

Match each web development scenario with the most appropriate selector type to use.

Items to match
β€’ Styling all paragraphs on the site
β€’ Styling warning messages that appear in various places
β€’ Styling the main page logo
β€’ Styling only paragraphs inside the footer
Definitions
β€’ p { }
β€’ .warning { }
β€’ #logo { }
β€’ footer p { }

Exercise 10 β€” Inheritance Challenge

Given the following HTML and CSS, what color will the text "CodΓ©mon Types" be?

<div id="main"> <section class="content"> <h1 class="title">CodΓ©mon Types</h1> </section> </div>#main { color: red; } .content { color: blue; } h1 { color: green; } .title { color: purple; }
Options
β€’ purple
β€’ green
β€’ blue
β€’ red

Hint : Think about how inheritance works with nested elements, and which selector has the most direct and specific impact on the h1 element.

Exercise 11 β€” CSS Selector Syntax

Complete the CSS selectors using the correct symbols to match the descriptions.

Hint : Each type of selector has its own syntax: element selectors use just the tag name, class selectors use a dot (.) prefix, and ID selectors use a hash (#) prefix.

Exercise 12 β€” Multiple Classes on HTML Elements

What is the correct way to add multiple classes to an HTML element?

Options
β€’ <div class="card highlight">Content</div>
β€’ <div class="card, highlight">Content</div>
β€’ <div class="card" class="highlight">Content</div>
β€’ <div class="card.highlight">Content</div>

Hint : Multiple classes should be separated by spaces within a single class attribute.

Exercise 13 β€” Multiple Classes Challenge

Given the following CSS and HTML, what color will the text "Pyrochu" be?

.card { color: black; } .fire-type { color: orange; } .legendary { color: purple; } .card.legendary { color: gold; } .fire-type.legendary { color: red; }<div class="card fire-type legendary">Pyrochu</div>
Options
β€’ red
β€’ gold
β€’ purple
β€’ orange

Hint : Consider the specificity of each selector. When multiple classes are combined in a selector, its specificity increases. Which selector is the most specific one that applies to this element?

Exercise 14 β€” Order of Importance in CSS

Match each factor with its level of importance in determining which CSS rules are applied (from most to least important).

Items to match
β€’ Highest Priority
β€’ Second Highest
β€’ Third Highest
β€’ Lowest Priority
Definitions
β€’ !important declaration
β€’ Inline styles (style attribute)
β€’ ID selectors (#id)
β€’ Universal selector (*)

Exercise 15 β€” Overriding Styles

You have this CSS rule that makes all paragraphs blue: p { color: blue; } Which selector should you use to make ONLY ONE specific paragraph red instead?

Options
β€’ #special-paragraph { color: red; }
β€’ p { color: red; }
β€’ * { color: red; }
β€’ paragraph { color: red; }

Hint : To override the style for just one element, you need a selector with higher specificity that targets only that element.

Exercise 16 β€” Source Order and the Cascade

Given the following CSS rules with identical specificity, which color will be applied?

/* styles.css */ .card { color: blue; } .card { color: red; } .card { color: green; }<div class="card">What color am I?</div>
Options
β€’ green
β€’ red
β€’ blue
β€’ All three colors blended together

Hint : When selectors have the same specificity, the cascade determines which style is applied. Think about the order in which the styles are defined in the stylesheet.

Exercise 17 β€” Best Practices for Selectors

Which is generally considered the BEST practice for styling common elements like buttons across a website?

Options
β€’ Use class selectors (e.g., .button)
β€’ Use element selectors (e.g., button)
β€’ Use ID selectors (e.g., #submit-button, #cancel-button)
β€’ Use inline styles on each button

Hint : Consider which selector type provides the best balance of reusability and specificity for common UI elements.

Exercise 18 β€” When to Use ID Selectors

What is the MOST appropriate use case for an ID selector in CSS?

Options
β€’ Styling a unique element that appears only once on the page, like the main header
β€’ Styling all buttons to have the same appearance
β€’ Styling paragraphs with similar formatting
β€’ Styling all elements of the same type

Hint : Consider what makes ID selectors different from class or element selectors, particularly their uniqueness requirement.

Exercise 19 β€” Specificity Challenge

Given these CSS rules and HTML element, what color will the text be?

p { color: black; } .text { color: blue; } #content { color: red; }<p id="content" class="text">What color am I?</p>
Options
β€’ red
β€’ blue
β€’ black
β€’ No color (default text color)

Hint : Remember the specificity hierarchy: ID selectors > Class selectors > Element selectors.

Exercise 20 β€” Inline Styles vs. External CSS

Which style would win in this situation?

/* In your external CSS file */ #message { color: blue; } .alert { color: red; } p { color: green; }<p id="message" class="alert" style="color: purple;">Important message</p>
Options
β€’ purple
β€’ blue
β€’ red
β€’ green

Hint : Consider where inline styles rank in the specificity hierarchy compared to ID, class, and element selectors.

Exercise 21 β€” The !important Declaration

Which of these CSS rules will take precedence, regardless of the others?

p { color: red; } .text { color: blue; } #paragraph { color: green; } p { color: purple !important; }
Options
β€’ p { color: purple !important; }
β€’ #paragraph { color: green; }
β€’ .text { color: blue; }
β€’ p { color: red; }

Hint : The !important declaration overrides normal specificity rules in CSS. It has the highest priority regardless of selector type.

Exercise 22 β€” HTML Structure and CSS Selectors

Given this HTML structure, which CSS selector would target ONLY the second paragraph?

<div> <p>First paragraph</p> <p id="special">Second paragraph</p> <p class="note">Third paragraph</p> </div>
Options
β€’ #special
β€’ p
β€’ .note
β€’ div p

Hint : Consider which selector would uniquely identify just the second paragraph without selecting any other paragraphs.

Exercise 23 β€” Which Approach is Best?

You need to style all the buttons across your website. Some are for submitting forms, others are for navigation. Which approach is generally considered best practice?

Options
β€’ Use a generic .btn class with modifiers like .btn-primary, .btn-secondary
β€’ Style the button element directly: button { ... }
β€’ Give each button a unique ID: #submit-button, #nav-button
β€’ Use deeply nested selectors: form div button, nav ul li button

Hint : Think about the balance between reusability, maintainability, and appropriate specificity for common UI elements.

Exercise 24 β€” Element vs Class Selectors

You want to style only SOME of the paragraphs on your page to have a red background. Which selector is MOST appropriate?

Options
β€’ A class selector: .highlight { }
β€’ An element selector: p { }
β€’ An ID selector: #paragraph { }
β€’ Inline styles on each paragraph

Hint : Consider which selector type allows you to selectively apply styles to some elements of the same type but not others.

Exercise 25 β€” CSS Selector Syntax

Which of the following is the correct syntax for selecting an element with the ID "header"?

Options
β€’ #header { }
β€’ header { }
β€’ .header { }
β€’ *header { }

Hint : Remember the correct prefix character to use for ID selectors in CSS.

Back to the course