Selectors Flashcards

(20 cards)

1
Q

What are CSS selectors?

A

Patterns used to match (or select) the elements you want to style. They can also be used in JavaScript to select DOM nodes.

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

What does the universal selector (*) match?

A

Elements of any type. It does not directly match pseudo-elements by itself.

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

How do you select an element by its class attribute?

A

Use a dot (.) followed by the class name, e.g. .spacious { margin: 2em; }

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

How do you select an element by its ID?

A

Use a hash (#) followed by the ID value, e.g. #maincontent { border: 1px solid blue; }

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

How do you chain multiple class selectors on one element?

A

Write the classes with no whitespace between them, e.g. li.spacious.elegant — this only matches elements that have both classes.

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

What is a type selector?

A

A selector that matches elements by their HTML tag name, e.g. h1, p, div.

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

What is the selector list (comma separator) used for?

A

Grouping multiple selectors that share the same declarations, e.g. h1, h2, h3 { font-family: sans-serif; }. All matching nodes are selected.

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

What happens if one selector in a selector list is invalid?

A

The entire style block is ignored — unless you use :is() or :where(), which accept forgiving selector lists and skip only the invalid selectors.

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

What is the difference between :is() and :where() regarding specificity?

A

The specificity of :is() equals its most specific argument, while :where() always has zero specificity (0-0-0).

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

How do attribute selectors work?

A

They match elements based on their attributes or attribute values, e.g. [type=”radio”] selects elements with type=”radio”.

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

How do you make an attribute selector case-insensitive?

A

Add the i modifier inside the brackets, e.g. [type=”a” i].

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

What is the descendant combinator?

A

A space between two selectors, e.g. div p — it selects all <p> elements that are descendants (at any depth) of a <div>.

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

What is the child combinator?

A

The > symbol, e.g. div > p — it selects only direct children, not deeper descendants.

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

What is the adjacent sibling combinator?

A

The + symbol, e.g. h1 + p — it selects the element immediately following the first element, sharing the same parent.

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

What is the general sibling combinator?

A

The ~ symbol, e.g. h1 ~ p — it selects all sibling elements that follow the first element (not just the immediately adjacent one).

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

What pseudo-class targets an element when a user hovers over it?

A

:hover — e.g. a:hover { color: red; }

17
Q

What is the difference between a pseudo-class and a pseudo-element?

A

A pseudo-class (single colon, e.g. :hover) selects elements in a certain state. A pseudo-element (double colon, e.g. ::before) selects a specific part of an element.

18
Q

What does the :nth-child() pseudo-class do?

A

Matches elements based on their position among siblings, using a formula like :nth-child(2n+1) for odd children.

19
Q

Why should *.warning and .warning be considered equivalent?

A

The asterisk is optional with simple selectors — both select all elements with class=”warning”.

20
Q

What does the :not() pseudo-class do?

A

It matches elements that do NOT match the selector argument, e.g. p:not(.intro) selects paragraphs without the intro class. The selectors inside :not() do contribute to specificity.