Skip to content

Commit f29b64e

Browse files
Sleepfuladamwathan
andauthored
Add arbitrary-variants section in arbitrary-values (tailwindlabs#1378)
* Add arbitrary-variants section in arbitrary-values * Update adding-custom-styles.mdx Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
1 parent e913586 commit f29b64e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ description: Best practices for adding your own custom styles to Tailwind.
44
---
55

66
import { TipGood, TipBad, TipCompat, TipInfo } from '@/components/Tip'
7+
import { SnippetGroup } from '@/components/SnippetGroup'
78

89
Often the biggest challenge when working with a framework is figuring out what you're supposed to do when there's something you need that the framework doesn't handle for you.
910

@@ -116,6 +117,33 @@ This can be useful for things like CSS variables as well, especially when they n
116117
</div>
117118
```
118119

120+
### Arbitrary variants
121+
122+
Arbitrary _variants_ are like arbitrary values but for doing on-the-fly selector modification, like you can with built-in pseudo-class variants like `hover:{utility}` or responsive variants `md:{utility}` but using square bracket notation directly in your HTML.
123+
124+
<SnippetGroup>
125+
126+
```html HTML
127+
<ul role="list">
128+
{#each items as item}
129+
<li class="**lg:[&:nth-child(3)]:hover:underline**">{item}</li>
130+
{/each}
131+
</ul>
132+
```
133+
134+
```css Generated CSS
135+
/* https://media.giphy.com/media/Sd3cd0SrUKZEyWmAlM/giphy.gif */
136+
@media (min-width: 1024px) {
137+
.lg\:\[\&\:nth-child\(3\)\]\:hover\:underline:hover:nth-child(3) {
138+
text-decoration-line: underline;
139+
}
140+
}
141+
```
142+
143+
</SnippetGroup>
144+
145+
Learn more in the [arbitrary variants](/docs/hover-focus-and-other-states#using-arbitrary-variants) documentation.
146+
119147
### Handling whitespace
120148

121149
When an arbitrary value needs to contain a space, use an underscore (`_`) instead and Tailwind will automatically convert it to a space at build-time:

0 commit comments

Comments
 (0)