Skip to content

CSS Selectors, Pseudoclasses, and Pseudoelements

Selector Type

Example

Note

Universal selector

*

/

Type selectors

b

div,p select all <div> elements and all <p> elements.

Class selectors

.classname

/

ID selectors

#idname

/

Descendant selectors

span em

Select all <em> elements who have a parent element of <span>.

Child selectors

div > em

Select all <em> elements who have a direct parent element of <div>

Adjacent sibling selectors

i + b

Select the <b> element who is directly after the <i> element, and meanwhile both the <i> and <b> elements should be within a same parent element.

Attribute selectors

a[href='info.htm']

/

Pseudoclasses

a:hover

/

Pseudoelements

p::first-letter

/

天上的神明与星辰,人间的艺术和真纯,我们所敬畏和热爱的,莫过于此。