Skip to content

Commit 230c683

Browse files
author
Isiah Meadows
authored
Update README.md
1 parent 0c6912e commit 230c683

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

README.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,40 +64,44 @@ console.log(output);
6464

6565
### Defining Custom Properties with `--*`
6666

67-
A custom property is any property whose name starts with two dashes (U+002D HYPHEN-MINUS). A property must be in a rule.
67+
A custom property is any property whose name starts with two dashes `--`. A property must be in a rule.
6868

69-
*Note: `:root` is nothing more than the selector for the root DOM node.*
69+
*Note: `:root` is nothing more than the selector for the root DOM node. Any other selector like `.class`, `#id`, or even `#foo ~ .bar > span.baz` works.*
7070

7171
```css
7272
:root {
7373
--foo-width: 100px;
7474
--foo-bg-color: rgba(255, 0, 0, 0.85);
7575
}
76-
```
77-
78-
You may also declare custom properties in a normal selector. Any other selector like `.class`, `#id`, or even `#foo ~ .bar > span.baz` works.
7976

80-
```css
8177
.foo {
8278
--foo-width: 100px;
8379
--foo-bg-color: rgba(255, 0, 0, 0.85);
8480
}
8581
```
8682

87-
A custom property can be declared multiple times, but only the last one takes precedence.
83+
Custom properties can be declared multiple times, but like variable scope in other languages, only the most specific one takes precedence.
8884

8985
```css
90-
:root {
91-
--foo-width: 100px;
92-
--foo-width: 200px; /* This is the declaration used. */
86+
:root: {
87+
--some-color: red;
9388
}
9489

9590
.foo {
96-
--foo-width: 100px;
91+
/* red */
92+
color: var(--some-color);
9793
}
9894

99-
.foo {
100-
--foo-width: 200px; /* This is the declaration used. */
95+
96+
.bar {
97+
--some-color: blue;
98+
/* blue */
99+
color: var(--some-color);
100+
}
101+
102+
.bar:hover {
103+
--some-color: green;
104+
/* Automically gets a `color: green;` declaration because we `--some-color` used within scope elsewhere */
101105
}
102106
```
103107

@@ -138,7 +142,7 @@ It's perfectly okay to declare CSS variables inside media queries and the like.
138142
}
139143
```
140144

141-
This will be transformed to:
145+
Will be transformed to:
142146

143147
```css
144148
.box {
@@ -167,7 +171,7 @@ Psuedo-classes are also dealt with correctly, because it's easy to statically de
167171
}
168172
```
169173

170-
This will be transformed to:
174+
Will be transformed to:
171175

172176
```css
173177
.foo {
@@ -350,7 +354,7 @@ Continue to the next section to see where some of these might be unsafe to do. T
350354

351355
# Caveats
352356

353-
When declaring a CSS variable inside one selector, but consume it in another, this does make an unsafe assumption which can be non-conforming in certain edge cases. Here is an example where these limitations unavoidably result in non-conforming behavior.
357+
When you declare a CSS variable inside one selector, but consume it in another, this does make an unsafe assumption about it which can be non-conforming in certain edge cases. Here is an example where these limitations result in non-conforming behavior.
354358

355359
Using the following CSS:
356360

0 commit comments

Comments
 (0)