News for hackers. Stuff that matters.
Re:Why Tailwind CSS Won by sod on Wednesday August 16, 2023 @05:24AM (#37144606)
If css had a strong opinion and better syntax for responsiveness by screen width, css frameworks were way less popular. Tailwind, bootstrap and co. aren't used to avoid writing css. It's used because writing `class="my-4 mb-sm-5 mb-lg-6"` is so much faster and easier then doing this with a bunch of media queries and a class name, that has to be unique, because css is a global scope nightmare.

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;
            }
        }
Re:Why Tailwind CSS Won by xigoi on Wednesday August 16, 2023 @05:34AM (#37144674)
> class="my-4 mb-sm-5 mb-lg-6"

I've seen Perl code that was more readable than this.

Re:Why Tailwind CSS Won by conradfr on Wednesday August 16, 2023 @06:29AM (#37145042)
If you know the convention it's quite easy.

I guess m = margin, y = y axis, b = bottom, sm/lg = screen size, 4/5/6 = size

Re:Why Tailwind CSS Won by xigoi on Wednesday August 16, 2023 @06:39AM (#37145114)
4/5/6 what? Bananas? And what exactly is “screen size”? Does it refer to physical size, or number of pixels? Does it count width, height, or both?
Re:Why Tailwind CSS Won by conradfr on Wednesday August 16, 2023 @07:02AM (#37145261)
These refers to customizable variables and breakpoints that everyone using the library and having done css would know and you can probably click on your IDE to get to their definition.

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.

Re:Why Tailwind CSS Won by deprecative on Wednesday August 16, 2023 @07:31AM (#37145474)
You're just using someone else's padding and margin classes. At least when you write your own it makes sense instead of Tailwind's alphabet soup bloat.
Re:Why Tailwind CSS Won by ajanuary on Wednesday August 16, 2023 @08:12AM (#37145833)
Not really. Tailwind lets you configure your own spacing and breakpoints. You get to pick what those numbers mean.
Re:Why Tailwind CSS Won by deprecative on Wednesday August 16, 2023 @05:45PM (#37154311)
That's just a CSS variable. You don't need Tailwind for that.
Re:Why Tailwind CSS Won by ajanuary on Thursday August 17, 2023 @05:57AM (#37159417)
Never said you did. I was just explaining that you aren't "using someone else's padding and margin classes".
Re:Why Tailwind CSS Won by cantSpellSober on Thursday August 17, 2023 @09:09AM (#37160995)
They are CJS modules or (ideally) Typescript. CSS custom properties (variables) are slightly different.

    import type { Config } from 'tailwindcss'
    
    export default {
      content: [],
      theme: {
        extend: {},
      },
      plugins: [],
    } satisfies Config
(not arguing for or against TW here)
Re:Why Tailwind CSS Won by dalmo3 on Wednesday August 16, 2023 @08:52AM (#37146302)
You don't need 5 question marks to tell us you don't know what breakpoints are.
Re:Why Tailwind CSS Won by xigoi on Wednesday August 16, 2023 @09:10AM (#37146522)
I know what breakpoints are. As far as I'm aware, there are no standard values for them.
Re:Why Tailwind CSS Won by arrowsmith on Thursday August 17, 2023 @06:13AM (#37159518)
Here, here are Tailwind's standard breakpoints:

      'sm': '640px',
      // => @media (min-width: 640px) { ... }

      'md': '768px',
      // => @media (min-width: 768px) { ... }

      'lg': '1024px',
      // => @media (min-width: 1024px) { ... }

      'xl': '1280px',
      // => @media (min-width: 1280px) { ... }

      '2xl': '1536px',
      // => @media (min-width: 1536px) { ... }
That's from the docs. https://tailwindcss.com/docs/screens

If you don't want those specific breakpoints in your project, you can override the defaults in `tailwind.config.js`.

Re:Why Tailwind CSS Won by deliriumchn on Wednesday August 16, 2023 @07:21AM (#37145390)
> If you know the convention it's quite easy.

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.

Re:Why Tailwind CSS Won by zztop44 on Wednesday August 16, 2023 @08:10AM (#37145816)
But isn’t BEM or a custom system of CSS variables strictly worse in this regard? Instead of knowing what class=“mb-4” means in Tailwind, they now need to know what class=“news-button” means in your specific application.
Re:Why Tailwind CSS Won by xigoi on Wednesday August 16, 2023 @10:16AM (#37147365)
class="news-button" means that it's a news button and will be styled the way that news buttons are styled. What's difficult about that?
Re:Why Tailwind CSS Won by cantSpellSober on Wednesday August 16, 2023 @08:56AM (#37146347)
I already know CSS, I don't want to learn another convention. I've learned Bootstrap, Tailwind, Foundation, Tachyons, Chakra, Bourbon...at each moment in time they were to be the "last" new CSS library we'd ever use.
Re:Why Tailwind CSS Won by jjdeveloper on Wednesday August 16, 2023 @05:43AM (#37144744)
That’s not tailwind code. Would be class="my-4 sm:mb-5 lg:mb-6"
Re:Why Tailwind CSS Won by wingspan on Wednesday August 16, 2023 @06:29AM (#37145043)
It’s worse than that, since you can’t use CSS variables inside a media query!
Re:Why Tailwind CSS Won by Sesse__ on Wednesday August 16, 2023 @07:16AM (#37145348)
Or, much shorter:

  .foo {
    padding: 1rem 0;
    @media (min-width: 500px) { padding-bottom: 1.5rem; }
    @media (min-width: 800px) { padding-bottom: 2rem; }
  }
Re:Why Tailwind CSS Won by progx on Wednesday August 16, 2023 @07:31AM (#37145473)
And you write this crap `class="my-4 mb-sm-5 mb-lg-6"`hundreds of times in complex applications or `class="foo"`?
Re:Why Tailwind CSS Won by yurishimo on Wednesday August 16, 2023 @08:59AM (#37146378)
How many components in your application actually need the exact same layout tweaks in every use instance?

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.

Re:Why Tailwind CSS Won by dmak on Wednesday August 16, 2023 @10:13AM (#37147320)
Do you practice atomic design? It shouldn't be an issue for you if you do
Re:Why Tailwind CSS Won by quickthrower2 on Thursday August 17, 2023 @10:08PM (#37170702)
I love tech’s endless fixes for self-induced problems.
Re:Why Tailwind CSS Won by emmacharp on Wednesday August 16, 2023 @07:36AM (#37145512)
You absolutely don't have to name everything in CSS. Naming components is sufficient. And you already need to do that. Using good HTML markup provides you with 80% of the styling hooks you need in a component. Specificity management and flexibility can be baked in too.

As for the media queries being hard/tiresome to write, don't we have IDE auto-completion for this exact purpose?