News for hackers. Stuff that matters.
Re:Play with TailwindCSS in the Browser by peterkelly on Friday June 10, 2022 @08:26AM (#31693079)
Any time spent learning tailwind is much better invested in learning plain CSS, since it's basically just syntactic sugar for style attributes. And learning CSS itself will be useful for many years to come, well beyond the lifetime of any given framework.

The browser's built-in CSS support is the framework, I don't understand why people try to build things like this on top of it unless they're adding real value.

Re:Play with TailwindCSS in the Browser by brightball on Friday June 10, 2022 @10:11AM (#31694484)
But it does add real value.

Aside from creating a standard naming scheme for your style guide, they also simplify specific CSS tag features by ensuring they can be consistent across browsers without you having to tweak each style.

Outside of that, they acknowledge that you're not going to use custom CSS tags that often because 9 times out of 10 you're going to style something in one place in a template and your programming language will repeat it for you...so there's no real value to creating a dedicated class.

Another that I've found over the lifecycle of a project is that developers forget what CSS is where and end up simply creating new classes for things that they need rather than trying to reuse existing ones...which leads to your CSS growing constantly over time. With Tailwind I rebuilt my entire personal site, brightball.com and ended up with 20 lines of custom CSS. This after restyling the entire site and making it responsive. And I was able to do all of it in an afternoon without ever having even made a responsive site before.

What they've done is created "Rails for Style Guides" and it works beautifully. The Refactoring UI book (fast read) from the authors of Tailwind goes into the importance and reasoning for everything they do and it makes absolutely perfect sense.

https://www.refactoringui.com/

Re:Play with TailwindCSS in the Browser by pocketsand on Friday June 10, 2022 @08:30AM (#31693115)
It's really not just syntatic sugar for style.

It's a design system as well as a set of utility classes. Consider the difference between

<span style="color: #cccccc">Gray text</span> and <span class="text-gray-700">Gray text</span>

In the former, you can't just redefine what gray means. You've hard set it to a value you need to keep track of and keep consistent. On the right, you can configure what "700" means, switch between a cool gray or a blue gray, etc.

Re:Play with TailwindCSS in the Browser by jakelazaroff on Friday June 10, 2022 @09:43AM (#31694076)
So use a custom property instead (don’t use inline styles tho):

    <span style=“color: var(--text-gray-700)”>Gray text</span>
Or use Sass or something. This problem has been solved for like 15 years.
Re:Play with TailwindCSS in the Browser by hbn on Friday June 10, 2022 @10:16AM (#31694533)
I want the styles to be in the template though, because I don't want to bounce back and forth between 2 files when designing a single UI. And it's not just inline styles, there's some things Tailwind can do that a style tag can't. Such as screen size breakpoints.

Here's how to make a div have 0.5rem of left/right padding on mobile, and 2rem on any screen larger:

    <div class="px-2 sm:px-8">
I'd much rather do this than mess with CSS's horrible media query syntax myself. And when I come back to this later, I don't have to cross-reference between (probably badly named) classes across 2 files to figure out how that div behaves.
Re:Play with TailwindCSS in the Browser by jakelazaroff on Friday June 10, 2022 @10:43AM (#31694911)
Okay, but now we’re back to Tailwind being back to syntactic sugar for styles (you can definitely put media queries in a style tag).

I disagree with your preference; all the classnames are not easily parseable and obscure the markup, and I much prefer the CSS media query syntax. But that’s, like, just my opinion, man. If you like it better, don’t let me stop you!

Re:Play with TailwindCSS in the Browser by skttl on Friday June 10, 2022 @11:31AM (#31695555)
>(you can definitely put media queries in a style tag)

How?

Re:Play with TailwindCSS in the Browser by jakelazaroff on Friday June 10, 2022 @11:47AM (#31695781)

    <style>@media (min-width: 100px) {}</style>
Re:Play with TailwindCSS in the Browser by azemetre on Friday June 10, 2022 @10:38AM (#31694829)
This is what tailwind does already. Colors are defined as design tokens in a config file:

https://tailwindcss.com/docs/customizing-colors#color-object...

Utility CSS is by far my favorite way to write CSS, especially in teams. It allows you to extract out multiple classnames that encapsulate all styles into a single classname.

Why would you use Sass when plain CSS does the job better? Tailwind is just normal CSS, all the build steps are ways of making your stylesheets more efficient and removing dead code but it's all still CSS no preprocessor necessary.

Re:Play with TailwindCSS in the Browser by my80thaccount on Friday June 10, 2022 @10:59AM (#31695131)
Those are both just opaque values, if you wanted to gsub them it would be exactly the same.