CSS Selectors Flashcards

1
Q

Type

A
  1. p {
  2. color: red;
  3. }
    This selects an element of the specified type based directly on providing the element name.
  4. <p>Lorem ipsum</p>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Class

A
  1. .thick {
  2. font-weight: bold;
  3. }
    This selects an element with matching class attribute name. This selector is indicated by the preceeding . dot (period).
  4. <span>I’m thick</span>
    You can apply a class name to as many elements as you like across the same page and across any pages in your website. This is a good selector for sprinkling the same style to many different elements.
    You can also apply more than one class to the same element. For example, let’s apply two classes to the same paragraph.
  5. .thick {
  6. font-weight: bold;
  7. }
  8. .alert {
  9. color: red;
  10. }
    To apply the two classes we simply use a space to separate their names.
  11. <p>Warning...</p>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

ID

A
  1. # box {
  2. background: blue;
  3. }
    This selects an element with matching id attribute name. This selector is indicated by the preceeding # hashtag symbol.
  4. <div>I'm a box</div>A single Id name should only be applied to one element per page.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Compound

A
  1. h1, h2, #box {
  2. font-family: Arial, Helvetica, sans-serif;
  3. }
    This selects all matched elements in the compound set. This selector is indicated by a , comma separating the selectors of the set. Each element within the comma separated list will be styled the same.
  4. <h1>Heading</h1>
  5. <h2>Subheading</h2>
  6. <div>I'm a box</div>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Descendent

A
  1. # nav li {
  2. background: blue;
  3. }
    This selects an element that is nested inside of the specified parent element. This selector is indicated by a keyboard space between the parent and the child to be selected.
  4. <ul>
    </ul>
  5. <li>child</li>
  6. </ul>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Child

A
  1. # list > li {
  2. border: 1px solid black;
  3. }
    This selects an element that is nested only one level deep inside of the specified parent element. It only selects direct children and not grandchildren. This selector is indicated by a > (greater than) symbol between the parent and the child to be selected.
  4. <ul>
    </ul>
  5. <li>child</li>
  6. <li>child
    </li>
  7. <ul>
    </ul>
  8. <li>grand child</li>
  9. </ul>
  10. </li>
  11. </ul>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Adjacent Sibling

A
  1. h3 + p {
  2. color: green;
  3. }
    This selects an element that appears directly after the former element assuming they are both siblings (in the same level of nesting, in the same parent). This selector is indicated by a + plus symbol between the former sibling and the selected element that follows.
  4. <h3>Heading</h3>
  5. <p>I'm a paragraph that is selected because I come directly after an h3.</p>
  6. <p>I'm not selected.</p>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

General Sibling

A
  1. h2 ~ p {
  2. color: black;
  3. }
    This selects all elements that appear directly after the former element. This selector is indicated by a ~ tilde symbol between the former sibling and the selected element that follows it.
  4. <h2>Sub heading</h2>
  5. <p>I'm selected because I appear after an h2.</p>
  6. <p>I'm also selected for the same reason, in fact any paragraphs on the rest of the page after the h2 will be selected.</p>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Universal

A
    • {
  1. color: orange;
  2. }
    This selects elements where the properties specified have not been styled by any other selectors. This selector is indicated by an * asterisk symbol.
  3. <h5>Sub heading</h5>We haven’t yet specified a color style for h5 anywhere else yet on our CSS so they will get the color orange now being covered under the universal selector.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Attribute

A
  1. img[alt=”Cat”] {
  2. border: 1px solid black;
  3. }
    This selects an element with a matching attribute value. This selector is indicated by [] square brackets, followed by the attribute property and value of the selected element within the brackets.
  4. <img></img>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

a[href^=”http”] The ^= caret symbol and equals sign

A

select elements that start with the matching value, such as <a></a>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

href=”http://google.com”>google.

p[class$=”dog”] The $= dollar and equals signs

A

select elements that end with the matching value, such as <p class="bigbdog">….</p>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

img[alt*=”love”] The *= asterisk and equals sign

A

select elements that have the matched characters appearing anywhere within the value, such as <img></img>.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

p[class~=”monkey”] The ~= tilde symbol and equals sign

A

select elements that contain the term within a space separated value, such as <p class="zoo monkey details">…</p>.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

p[class|=”birds”] The |= pipe symbol selects

A

elements that contain the term within a dash separated value, such as <p class="new-birds-today">…</p>.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Pseudo Class

A
  1. a:link {
  2. text-decoration: none;
  3. }
    This selects an element based on the unique relationship or state described in the selector. This selector is indicated by the : colon symbol, followed by the pseudo class that describes the element’s state or positioning amongst other elements.
  4. <a>About</a>
17
Q

a:link

A

selects links in their default state before the visitor has interacted with them.

18
Q

a:visited

A

selects links after the user has already clicked on them and is visiting that page again.

19
Q

a:hover

A

selects links when the user is hovering their mouse over the link.

20
Q

a:active

A

selects links for only the moment when the mouse button is pressed when clicking on the link.

21
Q

p:first-child

A

selects elements that are the first child when appearing inside a common parent. Such as <div><p>I’m selected</p><p>I’m not</p><p>Neither am I</p></div>

22
Q

p:last-child

A

selects elements that are the last child when appearing inside a common parent. Such as <div><p>I’m not selected</p><p>Neither am I</p><p>I’m selected</p></div>