Skip to content

Commit fc3b77d

Browse files
committed
document new @variant behavior where you can stack & compounds variants
1 parent b5f08df commit fc3b77d

1 file changed

Lines changed: 44 additions & 10 deletions

File tree

‎src/docs/adding-custom-styles.mdx‎

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ Use the `@variant` directive to apply a Tailwind variant within custom CSS:
328328

329329
</CodeExampleStack>
330330

331-
If you need to apply multiple variants at the same time, use nesting:
331+
If you need to apply multiple variants at the same time, stack them using the same syntax you would in HTML:
332332

333333
<CodeExampleStack>
334334

@@ -337,11 +337,9 @@ If you need to apply multiple variants at the same time, use nesting:
337337
.my-element {
338338
background: white;
339339

340-
/* [!code highlight:6] */
341-
@variant dark {
342-
@variant hover {
343-
background: black;
344-
}
340+
/* [!code highlight:4] */
341+
@variant hover:focus {
342+
background: black;
345343
}
346344
}
347345
```
@@ -351,10 +349,10 @@ If you need to apply multiple variants at the same time, use nesting:
351349
.my-element {
352350
background: white;
353351

354-
/* [!code highlight:7] */
355-
@media (prefers-color-scheme: dark) {
356-
&:hover {
357-
@media (hover: hover) {
352+
/* [!code highlight:8] */
353+
&:hover {
354+
@media (hover: hover) {
355+
&:focus {
358356
background: black;
359357
}
360358
}
@@ -364,6 +362,42 @@ If you need to apply multiple variants at the same time, use nesting:
364362

365363
</CodeExampleStack>
366364

365+
To apply the same styles for multiple variants, separate each variant with a comma:
366+
367+
<CodeExampleStack>
368+
369+
```css
370+
/* [!code filename:app.css] */
371+
.my-element {
372+
background: white;
373+
374+
/* [!code highlight:4] */
375+
@variant hover, focus {
376+
background: black;
377+
}
378+
}
379+
```
380+
381+
```css
382+
/* [!code filename:Compiled CSS] */
383+
.my-element {
384+
background: white;
385+
386+
/* [!code highlight:10] */
387+
&:hover {
388+
@media (hover: hover) {
389+
background: black;
390+
}
391+
}
392+
393+
&:focus {
394+
background: black;
395+
}
396+
}
397+
```
398+
399+
</CodeExampleStack>
400+
367401
## Adding custom utilities
368402

369403
### Simple utilities

0 commit comments

Comments
 (0)