You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I do love Tailwind and its concept because it feels more straightforward to style components directly on the DOM rather than naming classes and writing selectors that may not be valid when you refactor the structure of the DOM.
My issue is that, in a lot of cases, I come up with 20 to 30 classes per DOM. It's not a problem when it comes to performance because the classes are reusable, but it becomes hard to maintain this kind of cases. DOM contains now the layout structure, the data in it, and the style; so the whole thing becomes cluttered/bloated.
I like inline style, but dislike how every classes I use are unorganized in a single attribute. So I searched for alternatives and found that there are CSS selectors for targeting attributes with specific values, it's even possible to mimic the class attribute's behavior for other attribute.
For example, this selector [flex="flex-col"] would target DOMs that have the attribute flex with a value of "flex-col" but if you add other "classes" to it, it won't be targeted. So we have the ~= syntax. This means that `[flex~="flex-col"] will target every DOM that has an attribute flex that has in one of its keywords "flex-col", just like the class attribute.
The great thing is that, as long as you tell React or any framework what attributes are allowed, this code is valid and does not cause errors. It will be shipped to the browser successfully.
From my testings, Tailwind does detect the classes in other attributes and will ship the code related to the classes detected in the DOM, even if they are not in the class attribute. But it won't work, because Tailwind classes are not thought for that, their selector is still .whatever not [whatever~="whatever"].
I think it's great that CSS has a native feature to select DOM for their attributes, and has a syntax to mimic the class attribute's keyword behavior for other attributes, and I think it's a great idea because it's a non-breaking change, it adds a new way to write tailwind code without making the older code obsolete.
I'm a junior and I never looked in the Tailwind codebase so I can't understand how much effort it would require, but it makes the code so much more readable.
Sorry for my bad english. Thanks for reading, have a nice day.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I do love Tailwind and its concept because it feels more straightforward to style components directly on the DOM rather than naming classes and writing selectors that may not be valid when you refactor the structure of the DOM.
My issue is that, in a lot of cases, I come up with 20 to 30 classes per DOM. It's not a problem when it comes to performance because the classes are reusable, but it becomes hard to maintain this kind of cases. DOM contains now the layout structure, the data in it, and the style; so the whole thing becomes cluttered/bloated.
I like inline style, but dislike how every classes I use are unorganized in a single attribute. So I searched for alternatives and found that there are CSS selectors for targeting attributes with specific values, it's even possible to mimic the class attribute's behavior for other attribute.
For example, this selector
[flex="flex-col"]
would target DOMs that have the attribute flex with a value of "flex-col" but if you add other "classes" to it, it won't be targeted. So we have the~=
syntax. This means that `[flex~="flex-col"] will target every DOM that has an attribute flex that has in one of its keywords "flex-col", just like the class attribute.This code:
becomes this:
The great thing is that, as long as you tell React or any framework what attributes are allowed, this code is valid and does not cause errors. It will be shipped to the browser successfully.
From my testings, Tailwind does detect the classes in other attributes and will ship the code related to the classes detected in the DOM, even if they are not in the class attribute. But it won't work, because Tailwind classes are not thought for that, their selector is still
.whatever
not[whatever~="whatever"]
.I think it's great that CSS has a native feature to select DOM for their attributes, and has a syntax to mimic the class attribute's keyword behavior for other attributes, and I think it's a great idea because it's a non-breaking change, it adds a new way to write tailwind code without making the older code obsolete.
I'm a junior and I never looked in the Tailwind codebase so I can't understand how much effort it would require, but it makes the code so much more readable.
Sorry for my bad english. Thanks for reading, have a nice day.
Beta Was this translation helpful? Give feedback.
All reactions