You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: curriculum/challenges/english/25-front-end-development/review-css-variables/671a98fbaabfba994e3d9a7c.md
+68Lines changed: 68 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,75 @@ dashedName: review-css-variables
9
9
10
10
Review the concepts below to prepare for the upcoming quiz.
11
11
12
+
## CSS Custom Properties (CSS Variables)
12
13
14
+
-**Definition**: CSS custom properties, also known as CSS variables, are entities defined by CSS authors that contain specific values to be reused throughout a document. They are a powerful feature that allows for more efficient, maintainable, and flexible stylesheets. Custom properties are particularly useful in creating themeable designs. You can define a set of properties for different themes:
15
+
16
+
```css
17
+
:root {
18
+
--bg-color: white;
19
+
--text-color: black;
20
+
}
21
+
22
+
.dark-theme {
23
+
--bg-color: #333;
24
+
--text-color: white;
25
+
}
26
+
27
+
body {
28
+
background-color: var(--bg-color);
29
+
color: var(--text-color);
30
+
}
31
+
```
32
+
33
+
## The `@property` Rule
34
+
35
+
-**Definition**: The `@property` rule is a powerful CSS feature that allows developers to define custom properties with greater control over their behavior, including how they animate and their initial values.
36
+
37
+
```css
38
+
@property --property-name {
39
+
syntax: '<type>';
40
+
inherits: true | false;
41
+
initial-value: <value>;
42
+
}
43
+
```
44
+
45
+
- **`--property-name`**: This is the name of the custom property you're defining. Like all custom properties, it must start with two dashes. `--property-name` can be things like `<color>`, `<length>`, `<number>`, `<percentage>`, or more complex types.
46
+
- **`syntax`**: This defines the type of the property.
47
+
- **`inherits`**: This specifies whether the property should inherit its value from its parent element.
48
+
- **`initial-value`**: This sets the default value of the property.
49
+
- **Gradient Example Using the `@property` Rule**: This example creates a gradient that smoothly animates when the element is hovered over.
- **Fallbacks**: When using the custom property, you can provide a fallback value using the `var()` function, just as you would with standard custom properties:
0 commit comments