CSS Selectors Flashcards

1
Q

What is universal selector?

A
  • {
    color: black;
    }
    Selects every possible element on page.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is element selector?

A

Selects everything of a given type.

img {
width: 100px;
height: 200px;
}

This will select all img elements.

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

How do you combine multiple selectors?

A

Use a comma.
h1, h2 {
color: magenta;
}

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

How do you write an ID selector?

A

Use # along with the id name. ID specific to one element ID.

#search {
     color: blue;
}

This will style the element with the ‘search’ id only.

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

What is a class selector?

A

.tag {
color: red;
}

You can create a class on an element to specify/pinpoint styling (can be used on any element).
For example, if you have multiple <span> elements but only want to style certain ones, you can add a class tag to those <span class="tag">. then you would write
</span></span>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Write a descendant selector for all anchor tags nested in a list styled with text color blue with a wavy underline.

A

li a {
color: blue;
text-decoration: wavy underline;
}

**A space is nested but a comma will select both ‘li’ and ‘a’ elements.

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

Write an adjacent or combinator selector for a paragraph immediately preceded by a heading.

A

h1 + p {
color: red;
}

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

Write a direct child combinator to select only li’s that are direct children of a div element.

A

div > li {
color: white;
}

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

Write an attribute selector where all input type text is 300px wide and font color yellow.

A

input [type=”text”] {
width: 300px;
color: yellow;
}

  • *Applies to all attributes even class attributes.
  • **Check attribute selector MDN for variations.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are Pseudo Classes? Give examples.

A
Keyword/modifiers added to a selector that specifies a special state of the selected element(s).
\:active
\:checked
\:first
\:first-child
\:hover
\:not ( )
\:nth-child ( )
\:nth-of-type ( )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Style a button element that when hovered over the color changes to pink.

A

button:hover {
color: pink;
}

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

Style the item class with every other being green background with yellow text.

A

.item:nth-of-type(2n) {
background-color: green;
color: yellow;
}

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

Define Pseudo Elements and give examples.

A
Keywords added to a selector that lets you style a particular part of selected element(s).
\::after
\::before
\::first-letter
\::first-line
\::selection
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Define ‘The Cascade’

A

The order your styles are declared in and linked to matters. If multiple styles are declared in a sheet the styling follows the latest. Also if there are multiple style.css sheets the last on ‘link’ is followed.

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

What happens when you have conflicting styles targeting the same element?

A

Specificity will dictate which style will ultimately be applied to the page.

Remember ICE (ID>Class>Element)!!

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

What is the hierarchy of specificity in regards to selectors? Specificity score?

A

ID > Class > Element

I-C-E

17
Q

What are Inline styles?

A

Inline styles are used within the html doc and takes highest priority. Generally not best use.

18
Q

What does !important declaration do?

A

!important takes highest priority by ignoring specificity. Not best use.

19
Q

What is CSS inheritance?

A

Some CSS properties will be inherited by child elements. For instance, if I style the body element, everything within the body will be styled as such.

20
Q

What is CSS inheritance?

A

Some CSS properties will be inherited by child elements. For instance, if I style the body element, everything within the body will be styled as such. Inheritance will be from the closest parent element that is styled.

21
Q

How do you force certain elements to inherit?

A

button, input {
color: inherit;
}

**Not all properties are inheritable.