WEB-DEVELOPMENT-APPLICATIONS practice question 16 of 25

A web designer evaluates the following CSS rule: .head { color: #0000ff; } Which element is selected as a result?

Full set: 131 questions
Answer options
A:

A. <head>

B:

B. <H1>

C:

C. <div id="head">

D:

D. <div class="head">

Correct answer
Correct Answer:
D. D. <div class="head">
Explanation

In CSS, selectors are used to target HTML elements. A selector beginning with a period (.) is a class selector. The rule .head targets all HTML elements that have a class attribute with the value "head". Therefore,

is the only element that will be selected by this rule and have its text color changed to blue. Other selectors use different syntax: element selectors use the tag name (e.g., h1), and ID selectors use a hash symbol (e.g., #head).

Why Incorrect

A. would be selected by an element selector head, not a class selector .head.

B.

would be selected by an element selector h1, not a class selector .head.

C.

References

1. Mozilla Developer Network (MDN). (2023). Class selectors. In CSS: Cascading Style Sheets. Retrieved from https://developer.mozilla.org/en-US/docs/Web/CSS/Classselectors. (See the "Syntax" and "Examples" sections).

2. W3C. (2018, June 5). Selectors Level 3, Section 6.2: Class selectors. W3C Recommendation. Retrieved from https://www.w3.org/TR/selectors-3/#class-html.

3. Meyer, E. A., & Weyl, E. (2018). CSS: The Definitive Guide (4th ed.). O'Reilly Media. Chapter 2, "Selectors," section on "Class Selectors."

Scroll to Top