Skip to content

Commit e32c3d9

Browse files
authored
feat(curriculum): adding content to css variables review page (freeCodeCamp#57120)
1 parent 88e2ff6 commit e32c3d9

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

client/i18n/locales/english/intro.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2251,7 +2251,8 @@
22512251
"review-css-variables": {
22522252
"title": "CSS Variables Review",
22532253
"intro": [
2254-
"Review the CSS Variables concepts to prepare for the upcoming quiz."
2254+
"Before you are quizzed on the fundamentals of CSS variables, you first need to review.",
2255+
"Open up this page to review how to work with CSS custom properties(CSS variables) and the <code>@property</code> rule."
22552256
]
22562257
},
22572258
"quiz-css-variables": {

curriculum/challenges/english/25-front-end-development/review-css-variables/671a98fbaabfba994e3d9a7c.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,75 @@ dashedName: review-css-variables
99

1010
Review the concepts below to prepare for the upcoming quiz.
1111

12+
## CSS Custom Properties (CSS Variables)
1213

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.
50+
51+
```html
52+
<div class="gradient-box"></div>
53+
```
54+
55+
```css
56+
@property --gradient-angle {
57+
syntax: "<angle>";
58+
inherits: false;
59+
initial-value: 0deg;
60+
}
61+
62+
.gradient-box {
63+
width: 100px;
64+
height: 100px;
65+
background: linear-gradient(var(--gradient-angle), red, blue);
66+
transition: --gradient-angle 0.5s;
67+
}
68+
69+
.gradient-box:hover {
70+
--gradient-angle: 90deg;
71+
}
72+
```
73+
74+
- **Fallbacks**: When using the custom property, you can provide a fallback value using the `var()` function, just as you would with standard custom properties:
75+
76+
```css
77+
.button {
78+
background-color: var(--main-color, #3498db);
79+
}
80+
```
1381

1482
# --assignment--
1583

0 commit comments

Comments
 (0)