Selectors Flashcards

1
Q

What are the parts of a CSS rule?

A

A CSS rule consists of selectors and declarations. A declaration contains a property-value pair that applies styles to elements matched by the selector.

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

What does the universal selector (*) do?

A

It matches any element in the document.

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

What does a type selector do?

A

It matches an HTML element by its tag name.

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

How does a class selector work?

A

It selects elements with a specific class using the . character (e.g., .my-class).

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

How does an ID selector work?

A

It selects an element with a specific id using the # character (e.g., #rad).

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

How do attribute selectors work?

A

They match elements based on attributes, using square brackets ([ ]).

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

How do you select elements with a specific attribute value?

A

[attribute=’value’] (e.g., [data-type=’primary’]).

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

What do *, ^, and $ mean in attribute selectors?

A

*= matches a substring in the attribute value.
^= matches values that start with a specific string.
$= matches values that end with a specific string.

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

How do you apply styles to multiple selectors at once?

A

Use commas to separate selectors (e.g., h1, h2, .my-class { color: red; }).

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

What are pseudo-classes?

A

They style elements based on a state or user interaction (e.g., :hover, :nth-child(even)).

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

How do you style a link when it is hovered?

A

Use a:hover { /* styles */ }.

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

What are pseudo-elements?

A

They act like inserting new elements with CSS, using ::before or ::after.

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

What do ::before and ::after do?

A

::before inserts content before an element.
::after inserts content after an element.

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

What does the descendant combinator (whitespace ) do?

A

It selects elements inside a parent element (e.g., p strong { color: blue; }).

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

What does the child combinator (>) do?

A

It selects direct children of an element (e.g., div > p { color: red; }).

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

What does the + combinator do?

A

It selects the next immediate sibling of an element.

17
Q

What does the ~ combinator do?

A

It selects all following siblings that share the same parent.

18
Q

What are compound selectors used for?

A

To increase specificity by combining multiple selectors (e.g., a.my-class { color: red; }).