CSS (Selectors, Appearance, & Files) 2 — Questions and Answers
Question 1: Which selector targets an element with the exact id "header"?
- #header (Correct answer)
- .header
- header
- *header
Correct answer: #header
The hash (#) prefix selects an element by its id attribute.
Question 2: What does the selector "div p" match?
- Every <p> descendant inside any <div> (Correct answer)
- Only <p> that is a direct child of <div>
- A <div> followed by a <p>
- Elements with both div and p classes
Correct answer: Every <p> descendant inside any <div>
A space between selectors creates a descendant combinator matching any nested element.
Question 3: Which selector matches an <a> element only when the mouse is hovering over it?
- a:hover (Correct answer)
- a.hover
- a::hover
- a:active
Correct answer: a:hover
The :hover pseudo-class applies styles while the pointer is over the element.
Question 4: What is the correct syntax to link an external stylesheet in HTML?
- <link rel="stylesheet" href="style.css"> (Correct answer)
- <style src="style.css">
- <css href="style.css">
- <link rel="style" src="style.css">
Correct answer: <link rel="stylesheet" href="style.css">
External stylesheets use the <link> tag with rel="stylesheet" and an href attribute.
Question 5: Which property changes the text color of an element?
- color (Correct answer)
- text-color
- font-color
- foreground
Correct answer: color
The color property sets the foreground text color.
Question 6: What does the universal selector "*" select?
- All elements on the page (Correct answer)
- Only the root element
- Elements with no class
- The first element only
Correct answer: All elements on the page
The asterisk is the universal selector matching every element.
Question 7: Which selector targets elements with class "box" that are direct children of a <section>?
- section > .box (Correct answer)
- section .box
- section + .box
- section ~ .box
Correct answer: section > .box
The > combinator selects only direct children, not deeper descendants.
Which selector targets an element with the exact id "header"?