Docsity

CSS {selectors: cheat-sheet}, Lecture notes of Web Programming and Technologies

Toggle sidebar
bg1
CSS {selectors: cheat-sheet}
By Web Dev Simplified https://courses.webdevsimplified.com
Basic
Results
DescriptionCSSName
Selector
Universal *Select all elements a b c d
SelectorType div Select elements of that type
Select div elements a div c div
Selector
Class .c Select elements with that class
Select elements with the c class .a .b .c .d
Selector
Id #i Select elements with that id
Select elements with the i id
*It is best practice to not use ids in CSS #a #b #i #d
Combination
ResultsDescription
CSSName
Selector
Descendant div a
Select elements that are
descendants of the first
element
Select anchors that are inside a div
div
a b
aca d
Selector
Direct Child div > a Select elements that are direct
children of the first element
Select anchors that are direct children of
a div
div
a b
aca d
Selector
General Sibling div ~ a
Select elements that are
siblings of the first element
and come after the first
element
Selects all anchors that are siblings of a
div and come after the div
a div a a
Selector
Adjacent Sibling div + a
Select elements that are
siblings of the first element
and come directly after the
first element
Selects all anchors that are siblings of a
div and come directly after the div
a div a a
SelectorOr div, a Select elements that match
any selector in the list
Selects all anchors and all divs a div a b
SelectorAnd div.c Select elements that match all
the selector combinations
Selects all divs with the class c .a div.c .c div
pf3
Discount

On special offer

Partial preview of the text

Download CSS {selectors: cheat-sheet} and more Lecture notes Web Programming and Technologies in PDF only on Docsity!

CSS {selectors:^ cheat-sheet}

By Web Dev Simplified https://courses.webdevsimplified.com

Basic

Name CSS Description Results

Universal Selector * Select all elements^ a^ b^ c^ d

Type Selector div^

Select elements of that type

Select div elements a^ div^ c^ div

Class Selector .c

Select elements with that class

Select elements with the c class .a^ .b^ .c^ .d

Id Selector #i

Select elements with that id Select elements with the i id *It is best practice to not use ids in CSS

#a #b #i #d

Combination

Name CSS Description Results

Descendant Selector div a

Select elements that are descendants of the first element Select anchors that are inside a div

div

a b

a c a d

Direct Child Selector div > a

Select elements that are direct children of the first element Select anchors that are direct children of a div

div

a b

a c a d

Selector

General Sibling

div ~ a

Select elements that are siblings of the first element and come after the first element Selects all anchors that are siblings of a div and come after the div

a div a a

Selector

Adjacent Sibling

div + a

Select elements that are siblings of the first element and come directly after the first element Selects all anchors that are siblings of a div and come directly after the div

a div a a

Or Selector div, a

Select elements that match any selector in the list Selects all anchors and all divs

a div a b

And Selector div.c

Select elements that match all the selector combinations Selects all divs with the class c

.a div.c .c div

Attribute

Name CSS Description Results

Has Attribute [a]

Select elements that have that attribute Select elements with the a attribute

[a] [a=”1”] [c] d

Exact Attribute [a=”1”]

Select elements that have that attribute with exactly that value Select elements with the a attribute with a value of 1

[a] [a=”1”] [c] d

Begins With Attribute [a^=”1”]

Select elements that have that attribute which start with that value Select elements with the a attribute with a value that starts with 1

[a=”12”] [a=”21”]

Ends With Attribute [a$=”1”]

Select elements that have that attribute which end with that value Select elements with the a attribute with a value that ends with 1

[a=”12”] [a=”21”]

Substring Attribute [a*=”1”]

Select elements that have that attribute which contain that value anywhere Select elements with the a attribute with a value that contains a 1

[a=”12”] [a=”21”]

Pseudo Element

Name CSS Description Results

Before Selector div::before^

Creates an empty element directly before the children of selected element

div

before c after

After Selector div::after^

Creates an empty element directly after the children of selected element

div

before c after

Pseudo Class State

Name CSS Description

Hover Selector button:hover

Select elements that are hovered by the mouse Select buttons that are being hovered

Focus Selector button:focus

Select elements that are focused. Select buttons that are being focused *Focus is set by either tabbing to an element or clicking an element such as a button or anchor tag

Required Selector input:required

Select inputs that are required Select inputs with the required attribute

Checked Selector input:checked

Select checkboxes/radio buttons that are checked Select inputs that are checked

Disabled Selector input:disabled

Select inputs that are disabled Select inputs with the disabled attribute