Pseudo-classes, online
Six activities your students do on their own devices. See who's finished, and their scores.
Pseudo-classes in one minute
What students need to know
:last-child selects the final child element within its parent container. Pseudo-classes use a colon (:). A dot (.) selects a class attribute, not a state.
:hover responds to mouse position. :focus responds to keyboard or click focus. :first-child targets only the first child of a parent, not all matching elements.
Mistakes students make
- Pseudo-classes use a colon, not a dot. a.hover tries to match an element with class='hover'. The correct selector is a:hover.
- CSS declarations need a colon between the property and value. It should be border: 2px solid blue; not border 2px solid blue;.
- The CSS property is color (American English), not colour. It should be color: white; not colour: white;.
- CSS uses a colon between property and value, not an equals sign. It should be opacity: 0.8; not opacity = 0.8;.
What students will learn in this module
Every question in Module 39
Quick questions
- Which syntax correctly applies a pseudo-class?Aa:hover { color: red; }Ba.hover { color: red; }
- :hover activates when...Athe mouse pointer is over the elementBthe element receives keyboard focus
- Which pseudo-class targets an element while it is being clicked?A:activeB:focus
- li:first-child selects...Aevery li element on the pageBthe first li inside its parent
- Pseudo-classes use a single colon or double colon?ADouble colon — e.g. ::hoverBSingle colon — e.g. :hover
Key terms
Students type the meaning of:
pseudo-class
Match the pairs
a:hoverMatch it to what it doesinput:focusMatch it to what it doesTargets the last child element in a parentMatch it to what it doesTargets elements by their numeric position among siblingsMatch it to what it doesa.hover { color: red; }Match it to what it doesbutton::active { background: blue; }Match it to what it doesFill in the blanks
a:_____ { color: red; }Hint: Type the pseudo-class that activates when a mouse pointer moves over an element
input:_____ { outline: 2px solid blue; }Hint: Type the pseudo-class that activates when an element receives keyboard or click focus
li:___________ { font-weight: bold; }Hint: Type the pseudo-class that targets the first child element inside a parent
li:__________ { color: gray; }Hint: Type the pseudo-class that targets the last child element inside a parent
button:______ { background: green; }Hint: Type the pseudo-class that applies while a button is being clicked
Spot the error
Question 1
Aa.hover {B color: orange;C}
Question 2
Ainput:focus {B border 2px solid blue;C}
Question 3
Abutton:active {B background: darkblue;C colour: white;
Question 4
Aa:visited {B text-decoration: none;C color: purple;D opacity = 0.8;
Question 5
Ali:first-child {B font-size: 18px;C font-weight: bold;D color: navy;E text-align centre;
