Skip to main content

CSS Diner

Note: Everything in this document is based off of the CSS Diner game intended to help developers become more familiar with CSS selectors. This "companion" is simply meant to be used as a supplement/reference.

Goal of game: Select the "wiggling items" using CSS selectors.

Selectors: Go to the CSS selector descriptions and examples section to refresh your memory on a variety of CSS selectors.

Usage: For any given level, you are provided with a .gif illustrating what you are trying to select. Here is how you should go about using this companion if you do not simply go the site hosting the game:

  1. Watch: Watch the .gif to see what is wiggling.
  2. HTML Viewer: Open (i.e., click) the HTML Viewer to see what HTML actually makes up the .gif you saw in Step 1. This will be important because you will be trying to target or select named elements, and you may need to see the HTML to deduce these elements' names, what classes or attributes they may have, etc.
  3. Hint: Click the Hint if you need a nudge in the right direction. What you find in the hint will often be phraseology that more or less points you to a specific part of the CSS selector descriptions and examples section.
  4. CSS Viewer: Click the CSS Viewer to see one (or more) potential solutions. You may come up with completely different solutions! If so, consider making a pull request to this repo with your additional solution formatted as seen in the provided solution(s).

1 - Type

A

Selects all elements of type A. Type refers to the type of tag, so <div>, <p>, and <ul> are all different element types.


2 - Type

A

Selects all elements of type A. Type refers to the type of tag, so <div>, <p>, and <ul> are all different element types.


3 - ID Selector

#id

Selects an element with a specific id.


4 - Descendant Selector

A B

Selects all elements B that are children of A; that is, A B is how you select an element(s) B that is inside another element A.


5 - Combine Descendant and ID Selectors

#id A

You can combine any selector with the descendant selector.


6 - Class Selector

.classname

Select elements by their class. The class selector selects all elements with that class attribute. Elements can only have one ID, but many classes.


7 - Combining the Class Selector with Other Selectors

A.className

You can combine the class selector with other selectors, like the type selector.


8 - Levels 1-7 Overview

None (this level is a simple overview of lessons learned in the previous lessons).


9 - Combining Selectors with Commas

A, B

You can select all A and B elements (or all A, B, and C elements with A, B, C, etc.).


10 - Universal Selector

*

You can select all elements with the universal selector * (also known as a wildcard).


11 - Combine the Universal Selector

A *

This selects all elements inside of A.


12 - Adjacent Sibling Selector

A + B

This selects all B elements that direct follow A elements. Elements that follow one another are called siblings. They're on the same level or depth. In the HTML markup, elements that are siblings should have the same indentation level.


13 - General Sibling Selector

A ~ B

Selects all elements B that follow an element A; that is, you can select all siblings of an element that follow it. This is sort of like the adjacent sibling selector (i.e., A + B) except A ~ B gets all of the following sibling elements instead of just the direct next one.


14 - Child Selector

A > B

Selects all B that are direct children of A. You can select elements that are direct children of other elements. A child element is any element that is nested directly in another element. Elements that are nested deeper than that are called descendant elements.


15 - First Child Pseudo-selector

A:first-child

Selects all first-child elements that are of type A. A child element is any element that is directly nested in another element. You can combine this pseudo-selector with other selectors.


16 - Only Child Pseudo-selector

A:only-child

Selects any element A that is the only element inside of another one.


17 - Last Child Pseudo-selector

A:last-child

Selects any element A that is the last child of another element. You can use this selector to select an element that is the last child element inside of another element.


18 - Nth Child Pseudo-selector

:nth-child(A)

Selects the nth (i.e., 1st, 3rd, 12th, etc.) child element in another element.


19 - Nth Last Child Selector

:nth-last-child(A)

Selects the children from the bottom of the parent. This is like nth-child but counting from the back.


20 - First of Type Selector

A:first-of-type

Selects the first element of type A within another element.


21 - Nth of Type

A:nth-of-type(num)

Selects an element of type A based on its order in another element (or even or odd instances of that element).


22 - Nth of Type Selector with Formula

:nth-of-type(An+B)

The nth-of-type formula selects every nth element, starting the count at a specific instance of that element.


23 - Only of Type

:only-of-type

Selects the only element of its type within another element.


24 - Last of Type

:last-of-type

Selects each last element of that type within another element.


25 - Empty

:empty

Selects elements that don't have any other elements inside of them.


26 - Negation Pseudo-class

:not(X)

Selects all elements that do not match the negation selector.


27 - Attribute Selector (general)

[attribute]

Selects all elements that have a specific attribute. Attributes appear inside the opening tag of an element. For example: <span attribute="value"></span>. An attribute does not always have a value, it can be blank.


28 - Attribute Selector (specific)

A[attribute]

Selects all elements A that have a specific attribute.


29 - Attribute Value Selector

[attribute="value"]

Selects all elements that have a specific attribute value. Attribute selectors are case sensitive.


30 - Attribute Starts With Selector

[attribute^="value"]

Selects all elements with an attribute value that starts with specific characters.


31 - Attribute Ends with Selector

[attribute$="value"]

Selects all elements with an attribute value that ends with specific characters.


32 - Attribute Wildcard Selector

[attribute*="value"]

Selects all elements with an attribute value that contains specific characters.