-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Add first-child and last-child variants #1024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
If I understand correctly, this won’t have any If I would want that, I need to create a custom plugin that looks more like the |
|
Yeah variants (other than responsive which is sort of a special case) don't "stack" in Tailwind, so you'd have to create a new variant that combined the two states. Maybe one day we can come up with a good solution for stacking but I don't have any really great ideas yet 🤔 |
|
This is great. However, is there not a way to shorten the class names? |
|
Yeah think just going to go with |
|
@pxwee5 Agreed. To me the name |
|
@rebolyte Lot of people seem to interpret it that way which I find a bit surprising to be honest, since CSS works the same way. With Tailwind's variant prefixes I find it useful to read them like guard conditions.
Variants are always about querying some sort of state, not about traversing the document structure. |
|
I think what makes this one a bit more confusing than |
|
Changed to first/last. |
This PR adds new
first-childandlast-childvariants to the framework, but disabled by default for all core plugins.These allow you to apply a utility to an element only when it is the first child or last child of its parent. Very useful for things like "put a border between all of these items that are generated in a loop" for example:
Something worth emphasizing is that these variants apply to the child element itself, not to the children of the element with the utility. This is consistent with how other pseudo-class variants in Tailwind work, and how the
:first/last-childpseudo selectors work in CSS.Said again in code: