Commit de48a76
authored
Ensure opacity modifier with variables work with
* ensure opacity modifier variables work as expected
We use `color-mix()` in v4 which means that we can use this for the
opacity modifier. One thing we do already is convert values such as
`0.5` to `50%` because that's what the `color-mix()` function expects.
However, if you use a variable like this:
```html
<div class="[--opacity:0.5] bg-red-500/[var(--opacity)]"></div>
```
This currently generates:
```css
.bg-red-500\/\[var\(--opacity\)\] {
background-color: color-mix(
in srgb,
var(--color-red-500, #ef4444) var(--opacity),
transparent
);
}
.\[--opacity\:0\.5\] {
--opacity: 0.5;
}
```
Which won't work because the opacity variable resolves to `0.5` instead
of the expected`50%`.
This commit fixes that by always ensuring that we use `* 100%`.
- If you already had a percentage, we would have `calc(50% * 100%)`
which is `50%`.
- If we have `0.5` then we would have `calc(0.5 * 100%)` which is also
`50%`.
* wrap everything but percentages in `calc(… * 100%)`
* use `else if`
* update changelogcolor-mix() (tailwindlabs#13972)1 parent 992cf8d commit de48a76
File tree
3 files changed
+20
-3
lines changed- packages/tailwindcss/src
3 files changed
+20
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7673 | 7673 | | |
7674 | 7674 | | |
7675 | 7675 | | |
| 7676 | + | |
7676 | 7677 | | |
7677 | 7678 | | |
7678 | 7679 | | |
| |||
7792 | 7793 | | |
7793 | 7794 | | |
7794 | 7795 | | |
7795 | | - | |
| 7796 | + | |
| 7797 | + | |
| 7798 | + | |
| 7799 | + | |
| 7800 | + | |
| 7801 | + | |
| 7802 | + | |
| 7803 | + | |
| 7804 | + | |
7796 | 7805 | | |
7797 | 7806 | | |
7798 | 7807 | | |
| |||
8091 | 8100 | | |
8092 | 8101 | | |
8093 | 8102 | | |
8094 | | - | |
| 8103 | + | |
8095 | 8104 | | |
8096 | 8105 | | |
8097 | 8106 | | |
8098 | | - | |
| 8107 | + | |
8099 | 8108 | | |
8100 | 8109 | | |
8101 | 8110 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
140 | 147 | | |
141 | 148 | | |
142 | 149 | | |
| |||
0 commit comments