css_cheatsheet

This is an old revision of the document!


Selector Explanation
Navigation
> selects direct child
(space) selects any descendant
~ selects following sibling
+ selects direct following sibling
, separator for joined selectors
Attribute Matching
. selects by class
# selects by id
[] attribute selector
[attr] select elements that have attribute present (even if it's empty)
[attr=value] match exact attribute value
[attr=value i] i suffix turns any attribute match case insensitive
[attr*=value] match containing attribute value
[attr|=value] match exact ignoring “-suffixes” value
[attr^=value] match attributes that start with value
[attr$=value] match attributes that end with value
[attr~=value] match attributes that contain a word
Element Matching
:not() reverses selection
:has() select if element has a matching descendant
:is() apply multiple selectors
:first-child select if it's the first element in the group
:last-child select if it's the last element in the group
:nth-child() select if it's the Nth element, supports even, odd
:nth-last-child() like nth-child but reversed
:first-of-type select if it's the first element of that type in the group.
:last-of-type select if it's the last element of that type in the group.
:nth-of-type() select if it's the Nth element of that type in the group.
:only-of-type() select if it's the only element of that type in the group.
Non-standard Functions
::attr(name) select attribute value. Available in scrapy, parsel, Scrapfly SDK
:text select text value. Available in scrapy, parsel, Scrapfly SDK
  • css_cheatsheet.1742526443.txt.gz
  • Last modified: 2025/03/21 03:07
  • by root1