Cascading Style Sheets.
The name cascading comes from the specified priority scheme to determine which style rule applies if more than one rule matches a particular element
Source: Wikipedia
- External CSS
- Internal CSS
- Inline CSS
- Tag Name
- Class Name
- Id
- Attribute
p
- Selects<p>
elementsh1
- Selects<h>
elements
.phone
Selects elements with classphone
#phone
[style="display: none;"]
.heading.dark
Selects element with these two classeswikitable.sortable.plainrowheaders.jquery-tablesorter
selects elements with all these classes
h1,h2
Selectsh1
andh2
elements
*
Selects all elements
[href="https://www.google.com"]
[data-country]
[href^=tel]
[href$=es]
[href*=google]
- descendant
- child
- adjacent sibling
- general sibling
div p
selects all p
that are descedents (children, grandchildren, etc) of a div
tag
div > p
selects all p
that are children of a div
tag
div + p
selects ONE p
that is immediately AFTER div
tag
div ~ p
selects ALL p
that is immediately AFTER div
tag
td:last-child
Selects everytd
that is last child of it's parent
td:first-child
Selects everytd
that is first child of it's parent
Elements that are n-th child of it's element
link Wikipedia Countries
table.wikitable td:nth-child(3)
Selects population column
NOTE: table.wikitable td:nth-child(1)
doesnt select anything as the parent of td
is tr
, and tr
's first child is NOT td
but th
HINT: Think of girls and boys. A boy who was born after a girl, the boy is the second child. If you look for a first child who is a boy, you will not find anyone.