by sod · 3y ago · 0 comments
I mean, just look at it. You have to write all this crap in css just to achieve `class="my-4 mb-sm-5 mb-lg-6"`:
:root {
--breakpoint-sm: 500px;
--breakpoint-lg: 800px;
}
.foo {
padding: 1rem 0;
}
@media (min-width: var(--breakpoint-sm)) {
.foo {
padding-bottom: 1.5rem;
}
}
@media (min-width: var(--breakpoint-lg)) {
.foo {
padding-bottom: 2rem;
}
}I've seen Perl code that was more readable than this.
I don't know Tailwind but with Bootstrap it would be m = margin, y = y axis, b = bottom, sm/lg = screen size, 4/5/6 = size
This is exactly the problem. Humans write code for humans, not for tailwind specialists and bots. It should be clear and easy to read unless there is a valid reason for weird code (optimisations, hacks that don't work otherwise etc). Tailwind introduces yet another convention where it is absolutely pointless to do so.
Personally I think that's way better than putting padding & margin in your own css classes.
It actually cuts down a lot on the custom css you need to write and also helps having a uniform design.
There are some properties of CSS that are more static across screen sizes. Colors, borders, backgrounds, font-size (debatable!), animations, and maybe even some high level layouts (12 column grid, etc).
The rest of CSS is minute positioning via padding, margins, and widths. Often you need to customize those details to use slightly different values dependent on context within the application itself. This is where utility classes shine.
.foo {
padding: 1rem 0;
@media (min-width: 500px) { padding-bottom: 1.5rem; }
@media (min-width: 800px) { padding-bottom: 2rem; }
}As for the media queries being hard/tiresome to write, don't we have IDE auto-completion for this exact purpose?