CSS Flashcards

(56 cards)

1
Q

What does CSS stand for?

A

Cascading Style Sheets.

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

What is the purpose of CSS?

A

To style and layout HTML elements.

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

What is the difference between class and ID selectors?

A

ID is unique (#id), class can be reused (.class).

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

What is the difference between inline, internal, and external CSS?

A

Inline is in the tag, internal is in <style>, external is in a separate .css file.</style>

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

What is specificity in CSS?

A

The rules that determine which CSS rule is applied.

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

What is the universal selector?

A

* – it selects all elements.

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

What does the > selector do?

A

Selects direct child elements.

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

What does the + selector do?

A

Selects the next sibling element.

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

What does the ~ selector do?

A

Selects all subsequent siblings.

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

What is an attribute selector?

A

Selects elements based on attributes, e.g., [type='text'].

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

What are the parts of the CSS box model?

A

Content, padding, border, and margin.

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

What does box-sizing: border-box do?

A

Includes padding and border in the element’s total width and height.

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

What is the difference between margin and padding?

A

Margin is space outside, padding is space inside the border.

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

How do you center a block element?

A

margin: auto and define width.

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

How do you center an inline element?

A

Use text-align: center on the parent.

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

What are the values of the position property?

A

static, relative, absolute, fixed, sticky.

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

What does position: absolute mean?

A

Element is positioned relative to the nearest positioned ancestor.

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

What does position: fixed mean?

A

Element stays fixed relative to the viewport.

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

What does position: relative mean?

A

Element is positioned relative to its normal position.

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

What does position: sticky do?

A

Element toggles between relative and fixed depending on scroll position.

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

What is Flexbox used for?

A

To layout elements in a flexible and responsive way.

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

What does justify-content control?

A

Alignment of items on the main axis.

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

What does align-items control?

A

Alignment of items on the cross axis.

24
Q

What does flex-grow do?

A

Defines the ability of a flex item to grow.

25
What does `flex-shrink` do?
Defines the ability to shrink if needed.
26
What is CSS Grid?
A 2D layout system for arranging elements in rows and columns.
27
What does `grid-template-columns` do?
Defines the column structure.
28
What does `grid-gap` or `gap` do?
Defines spacing between grid items.
29
How do you span multiple columns in grid?
Use `grid-column: start / end`.
30
Can Grid and Flexbox be used together?
Yes, you can nest one inside the other.
31
What properties are inherited by default?
Text-related properties like font, color.
32
How can you increase specificity?
Use more specific selectors or add `!important`.
33
What does `!important` do?
Forces a rule to override all others.
34
How to override CSS from a library?
Use more specific selectors or `!important`.
35
What is the order of specificity?
Inline > ID > class > element selector.
36
What is a media query?
Used to apply styles based on screen size or device.
37
How to target mobile devices?
`@media (max-width: 600px) {}`
38
Can you combine media queries?
Yes, using `and`, `or`, `not`.
39
What is the difference between `em` and `rem` in media queries?
`em` is relative to parent; `rem` is relative to root.
40
What is the difference between transition and animation?
Transition is triggered by change; animation runs automatically.
41
What is `@keyframes` used for?
To define the steps of an animation.
42
How do you make a smooth hover effect?
Use `transition` with duration.
43
What does `animation-fill-mode: forwards` do?
Keeps final state after animation ends.
44
What is the difference between px, %, em, and rem?
`px` is fixed; `%` is relative to parent; `em` and `rem` are relative to font sizes.
45
When should you use `vh` and `vw`?
To size elements relative to viewport height/width.
46
What does `calc()` do in CSS?
Performs calculations to set property values.
47
How does stacking context work?
It's a 3D concept that determines element visibility using `z-index`.
48
What is reflow and repaint?
Reflow recalculates layout; repaint redraws pixels.
49
How to make a website responsive?
Use flexible layouts, media queries, and relative units.
50
What is the default position of an element?
`static`.
51
How to hide an element but keep it in the flow?
Use `visibility: hidden`.
52
How to hide it and remove from flow?
Use `display: none`.
53
What does `opacity: 0` do?
Hides element visually but it's still clickable.
54
What is the difference between `none`, `hidden`, and `opacity: 0`?
`none` removes, `hidden` hides visually but keeps space, `opacity` keeps space and interaction.
55
What is a pseudo-element?
`::before`, `::after` – lets you style part of an element.
56
What is a pseudo-class?
`:hover`, `:nth-child`, `:focus` – applies styles based on state.