-
Here is a tailwind play example of what I'm working on: My goal is to be able to add shape dividers between elements. I want to be able to add an element between my two elements to specify which shape to use. Using a tailwind utility class I can set the "size" of the divider such as With
This is needed to ensure it looks like the backgrounds flow under each other. The issue is that there is no actual previous selector in css. The best you can do is I could get this working if I manually defined the divider sizes I'm allowed to use, but I'm not a huge fan of that. I'm wondering if there's any tailwind magic that can be used here to autogenerate those needed classes. Or if anyone else has a clever idea on how to make this work. TLDR: Is there a way to automate the generation of this kind of code:
Previous attempt:I originally was just setting the divider on the previous element which is easy to get working as it only requires the next sibling selector. This felt confusing however as its setting the divider after the element. I often was going to the wrong element to modify the divider then remembering I need to actually go to the previous element. Moving it to its own element in between makes the most sense and means individual components don't know about the divider being used. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Basically, I'm hoping theres a way to get tailwind to generate an additional global class when a utility class is used:
Obviously that doesn't work as its scoped to the element and not global, but I hope that gets the gist across. I feel like this would have been possible with a JS tailwind v3 plugin so I'm curious if theres a way to do this in v4. |
Beta Was this translation helpful? Give feedback.
-
You could consider adding the |
Beta Was this translation helpful? Give feedback.
You could consider adding the
.accepts-divider
inside the@utility
, and having the nesting&
anchor inside:has()
: https://play.tailwindcss.com/2qxwuIZIc1?file=css