Complete all 32 levels of the CSS Diner tutorial. Reference MDN CSS Selectors
Type Selector: select elements by their type
A
div, p and ul are all different element types.plateSame as above
ID Selector: select elements with an ID
#id
#fancyDescendant Selector: select an element inside another element
A B
plate appleCombine the Descendant & ID Selectors: you can combine any selector with the descendent selector.
#id A
select the pickle on the fancy plate: #fancy pickle
Class Selector: select elements by their class
.classname
.smallCombine the Class Selector: you can combine the class selector with other selectors, like the type selector.
A.classNameSelect the small oranges in the bentos: bento orange.small
Comma Combinator: combine, selectors, with… commas!
A, B
plate, bentoUniversal Selector: you can select everything!
*
*Combine the Universal Selector
A *
plate *Adjacent Sibling Selector: select an element that directly follows another element
A + B
plate+appleGeneral Sibling Selector: select elements that follows another element
A ~ B
Adjacent Selector (A + B) except it gets all of the following elements instead of one.bento~pickleChild Selector: select direct children of an element
A > B
plate>appleFirst Child Pseudo-selector: select a first child element inside of another element
:first-child
orange:first-childOnly Child Pseudo-selector: select an element that are the only element inside of another one.
:only-child
plate apple, plate pickle:only-childLast Child Pseudo-selector: select the last element inside of another element
:last-child
apple:last-child, pickle:last-childNth Child Pseudo-selector: select an element by its order in another element
:nth-child(A)
plate:nth-child(3)Nth Last Child Selector: select an element by its order in another element, counting from the back
:nth-last-child(A)
bento:nth-last-child(3)First of Type Selector: select the first element of a specific type
:first-of-type
apple:first-of-typeNth of Type Selector: selects a specific element based on its type and order in another element - or even or odd instances of that element.
:nth-of-type(A)
select all even plates: plate:nth-of-type(even)
Nth-of-type Selector with Formula: the nth-of-type formula selects every nth element, starting the count at a specific instance of that element.
:nth-of-type(An+B)
select every 2nd plate, starting from the 3rd: plate:nth-of-type(2n+3)
Only of Type Selector: select elements that are the only ones of their type within of their parent element
:only-of-type
plate apple:only-of-typeLast of Type Selector: select the last element of a specific type
:last-of-type
last-of-type, apple:last-of-typeEmpty Selector: select elements that don’t have children
:empty
bento:emptyNegation Pseudo-class: select all elements that don’t match the negation selector
-:not(X)
apple:not(.small)Attribute Selector: select all elements that have a specific attribute
[attribute]
span attribute="value". An attribute does not always have a value, it can be blank!<apple for="name"/>: [for]Attribute Selector: select all elements that have a specific attribute. Combine the attribute selector with another selector (like the tag name selector) by adding it to the end.
A[attribute]
select plates for sarah and luke only: plate[for]
Attribute Value Selector: select all elements that have a specific attribute value
[attribute="value"]
[for="Vitaly"]Attribute starts With Selector: select all elements with an attribute value that starts with specific characters
[attribute^="value"]
select the items for names that start with “Sa”: [for^="Sa"]
Attribute Ends With Selector: select all elements with an attribute value that ends with specific characters
[attribute$="value"]
Select the items for names that end with ‘ato’: [for$="ato"]
Attribute Wildcard Selector: select all elements with an attribute value that contains specific characters anywhere
[attribute*="value"]
class, href or src attributes.[for*="obb"]