CSS Flashcards

(19 cards)

1
Q

:has()

A

:has() HTML:

<li>
<p>First paragraph</p>
<p>Second paragraph</p>
</li>

<li>
<p>Only one paragraph</p>
</li>

:has() CSS:

li:has(p + p) {
color: rgb(27, 179, 179);
}

This selectslielements that have two consecutivepelements as direct children.

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

:is()

A

Suppose you have a website with multiple sections like<section> <article> <aside> <nav>, and you want to style all headings (h1 h2 h3 h4 h5 h6) within these sections uniformly.

Without:is()

You would typically write a long list of selectors:

section h1, section h2, section h3, section h4, section h5, section h6,
article h1, article h2, article h3, article h4, article h5, article h6,
aside h1, aside h2, aside h3, aside h4, aside h5, aside h6,
nav h1, nav h2, nav h3, nav h4, nav h5, nav h6 {
color: #BADA55;
}

With:is(), you can simplify this to:

:is(section, article, aside, nav) :is(h1, h2, h3, h4, h5, h6) {
color: #BADA55;
}

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

What is the CSS box model?

A

Every element is a rectangular box: content → padding → border → margin. Total rendered size depends on box-sizing.

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

What is the difference between box-sizing: content-box and border-box?

A

content-box (default): width = content only; padding and border are added on top. border-box: width includes padding + border.

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

What are the main Flexbox axis concepts?

A

Main axis: direction of flex items (set by flex-direction). Cross axis: perpendicular. justify-content aligns on main; align-items on cross.

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

What does flex: 1 mean?

A

Shorthand for flex-grow: 1; flex-shrink: 1; flex-basis: 0% — item grows to fill available space equally with siblings.

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

What is the difference between align-items and align-self in Flexbox?

A

align-items sets the default alignment for all children on the cross axis. align-self overrides it for a single child.

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

What is CSS Grid and how does it differ from Flexbox?

A

Grid is 2D (rows + columns simultaneously). Flexbox is 1D (row or column). Use Grid for overall page layout; Flexbox for component-level alignment.

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

How do you create a 3-column equal-width grid in CSS?

A

grid-template-columns: repeat(3, 1fr)1fr distributes free space equally.

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

What is a stacking context in CSS?

A

An element forming its own z-index layer. Created by: position + z-index (non-auto), opacity < 1, transform, filter, will-change, isolation: isolate.

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

How does CSS specificity work?

A

Inline styles > ID selectors > class/attribute/pseudo-class > element selectors. Equal specificity → later rule wins.

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

What is the CSS cascade?

A

Algorithm resolving rule conflicts: origin (user-agent < author < inline) → specificitysource order.

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

What are CSS custom properties (variables)?

A

Defined with --name: value in a selector scope; used with var(--name). They cascade and inherit like other CSS properties.

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

What is the difference between CSS transition and @keyframes animation?

A

transition: animates between two states triggered by a property change. @keyframes + animation: multi-step animation with full control over intermediate states.

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

Which CSS properties are GPU-composited and cheap to animate?

A

transform and opacity — they skip layout and paint, handled entirely by the compositor thread. Avoid animating width, height, top, left.

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

What is the difference between visibility: hidden and display: none?

A

visibility: hidden: element is invisible but still occupies space. display: none: element is removed from layout (no space).

17
Q

What is position: sticky?

A

Element is positioned normally until a scroll threshold — then it sticks relative to the nearest scrolling ancestor. Requires a top/bottom value.

18
Q

What does z-index apply to?

A

Only elements with position other than static (or certain properties creating a stacking context). Higher z-index = painted on top within the same stacking context.

19
Q

What are CSS pseudo-elements vs pseudo-classes?

A

Pseudo-class (:hover, :nth-child): targets element in a state. Pseudo-element (::before, ::after): targets a part of the element or creates a virtual child.