Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I think the fantastic thing about is the natural feeling constraints that it gives you, and not having to think about naming stuff or building out a CSS project (with standards etc) that scales at-all well (which is often a suprising amount of fuckery).

If you're using styled components and you want a small margin you have to do something along the lines of.

    const ThingWithMargin = div.styled`
      margin: ${margins[1]}
    `;

Presuming you've set up a file full of font sizes, margins, paddings.

In TailwindCC you get a bunch of very sane, well picked defaults chosen for you for free, by default. You write in a simple DSL and don't have to worry. You can update the defaults as you see fit, too.

    <div className="m-1" />
This has autocomplete, etc etc.

IF you don't want the clutter of all these utilities, you can abstract them away into smaller components as you already should be doing. You build your component library with speed and can focus on the actually interesting parts of your system as opposed to wasting time naming stuff or pissing about with CSS.

And of course, if your div is reused a lot, you naturally abstract it into a component at a time that suits you!

I'd say try just using for a project or two and you suddently realise you were wasting a whole lot of time and effort before.

Anything truly dynamic calculated can go also into a style= prop. They work great together!

E.g. here's a progress bar I made for a thing:

    <div
      ref={ref}
      className="w-full relative cursor-pointer -mt-1 -mb-1.5 h-3.5"
      onMouseDown={onMouseDown}>
      <div className="absolute h-1 top-1 bg-gray-600 bottom-0 left-0 right-0" />
      <div
        className="absolute h-1 top-1 bottom-0 left-0 bg-gray-200"
        style={{
          width: `${(currentTime / duration) * 100}%`,
        }}></div>
    </div>
I was so sick of working web because it felt like working in CSS was a total footgun unless you spend a lot of time making a solution that does things right. Now I find working on web projects a joy again.


When I write a component that takes a smaller margin I write something like this:

    my-component {
      margin-inline: var(--margin-thin);
    }
If I want this dense notation I can name the custom property `--m-1`. In most IDEs (or language servers) I’ve tried custom properties also have autocomplete.

That is I use CSS custom properties inside component scoped styles. (Component scoped styles is what I call the general idea that React’s styled components are implementing, but Vue’s SFC and the shadow DOM scope the styles to the component at hand equally well).

I’m not saying “Don’t use Tailwind; use custom properties instead”. But for those of us that don’t like the idea that Tailwind brings, there are options, and we are perfectly happy with what we got.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: