Question about new addVariant API #6757
-
(attn @RobinMalfait) When using the new |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey! Thank you for your question! Maybe we can optimize this internally, but in most cases using addVariant('foo', '&[foo="bar"]')
addVariant('bar', '[foo="bar"]&') And have the following html: <div class="group p-12">
<div foo="bar" class="foo:group-hover:text-green-500">Hello world</div>
<div foo="bar" class="bar:group-hover:text-green-500">Hello world</div>
</div> Then we would generate the following CSS: .group:hover .foo\:group-hover\:text-green-500[foo="bar"] {
--tw-text-opacity: 1;
color: rgb(34 197 94 / var(--tw-text-opacity));
}
[foo="bar"].group:hover .bar\:group-hover\:text-green-500 {
--tw-text-opacity: 1;
color: rgb(34 197 94 / var(--tw-text-opacity));
} So in this case, if you are combining it with a If you look at the generated css, then you will see that in the first scenario, the div element with Play: https://play.tailwindcss.com/Lef1CdGvCk More info on this can be found here: https://tailwindcss.com/docs/hover-focus-and-other-states#ordering-stacked-modifiers So in short I would recommend to put the |
Beta Was this translation helpful? Give feedback.
Hey! Thank you for your question!
Much appreciated! 🙏
Maybe we can optimize this internally, but in most cases using
&[foo="bar"]
is currently the best way of defining new variants. However, it also depends a bit on your use case. This is because&
will be replaced by the parent selector. So for example if we define 2 variants likefoo
andbar
:And have the following html:
Then we would generate the following CSS: