CSS Pseudo-classes
A pseudo-class is used to define a special state of an element.
For example, it can be used to:
Style an element when a user mouses over it
Style visited and unvisited links differently
Style an element when it gets focus
The syntax of pseudo-classes:
selector:pseudo-class {
property: value;
}
CSS Pseudo Classes
Selector
Example
Example description
p:nth-last-child(2)
Selects every <p> element that is the second child of its parent, counting from the last child
p:nth-last-of-type(2)
Selects every <p> element that is the second <p> element of its parent, counting from the last child
p:nth-of-type(2)
Selects every <p> element that is the second <p> element of its parent
#news:target
Selects the current active #news element (clicked on a URL containing that anchor name)
Last updated