Skip to content

Commit a6040fa

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

2 files changed

Lines changed: 46 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

src/docs/functions-and-directives.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ Use the `@variant` directive to apply a Tailwind variant to styles in your CSS:
9393
}
9494
```
9595

96+
You can also stack variants like `@variant hover:focus { … }`, or apply the same styles to multiple variants with `@variant hover, focus { … }`.
97+
9698
Learn more using variants in the [using variants documentation](/docs/adding-custom-styles#using-variants).
9799

98100
<h3 id="custom-variant-directive">

0 commit comments

Comments
 (0)