2

Which CSS frameworks are you using and why?

 1 year ago
source link: https://dev.to/clarycodes/which-css-frameworks-are-you-using-and-why-3j1h
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Which CSS frameworks are you using and why?CollapseExpand

Tailwind

I wouldn't use it outside of atomic design. Atomic Design is a must.

Comment button Reply

CollapseExpandCollapseExpand

Author

Jun 11

Yeah I also think Tailwind is the framework I will seriously consider. I suppose it's time to switch to PostCSS.

Comment button Reply

CollapseExpand

With "postcss-mixins" you also get either SASS-like mixin syntax with just PostCSS or JS functions as mixins.

For variables, you can use either CSS custom properties with var() or "postcss-simple-vars" for SASS-like variables, and "postcss-nested" SASS-like nested style syntax.

Definitely worth at least playing with.

Thread

Thread

Author

Jun 13

This is good to know because I'm using variables, nested selectors and mixins a lot to keep myself organized with SASS. Whenever I'm trying out a framework, especially a utility-class framework I'm really struggling with this. 😂 PostCSS plugins might help though.

Thread

Thread

Definitely if you're looking to make the switch. The syntax isn't 1-to-1, but it's very close.

Comment button Reply

CollapseExpand

It is a different approach. Everyone seems to hate on it and disagree with me here. People will call you an idiot lol.

Comment button Reply

CollapseExpand

I've been using bootstrap all the time, but Tailwind look nice. Maybe I'll try it sometime.

Comment button Reply

CollapseExpand

CollapseExpand

Instead of SASS/SCSS, I mostly only use css variables. So I appreciate CSS frameworks using them too.

Regarding the framework itself I use mainly Bulma, partly because it's work related, and I find it "ok". It's on the simpler side.

I also consider Bootstrap to be a de-facto standard. I don't think you can go wrong with it. It has everything you need, very themable, a very large ecosystem, community, and so on.

For mini projects, I enjoy MVP.css . It's super minimalistic but sometimes it's enough for small stuff.

Lastly, I profoundly dislike Tailwind.

Comment button Reply

CollapseExpand

Author

Jun 11

What do you dislike about Tailwind? I actually think Tailwind will replace Bootstrap as standard framework soon. 😅

Comment button Reply

CollapseExpand

To me tailwind just feels like inline styles. Why do I need tailwind for that? Having a div like <div class="relative p-3 col-start-1 row-start-1 flex flex-col-reverse rounded-lg bg-gradient-to-t from-black/75 via-black/0 sm:bg-none sm:row-start-2 sm:p-0 lg:row-start-1"> is just annoying IMHO (this example is taken from their own website). I would rather have something semantically meaningful like <div class="adjusting-layout"> that is reusable and leave the styling in the stylesheet. I just like it to have a relatively clean HTML and reusable classes.

Thread

Thread

Damn, I'm not the only one who doesn't see the difference between tailwind and inline CSS :)

Thread

Thread

Author

Jun 12

Yeah, I'm using Tailwind for my current project and I've also noticed this. I think originally external CSS stylesheets got invented to separate the styles from the HTML. Tailwind kind of reverses that, even if its only on the development side. I miss being able to apply styles to entire groups of elements which is way faster.

Thread

Thread

No, most people see the similarity when it's done like that. Most people don't think it's a problem though.

You can use it more like regular separate styles - i.e. you make a stylesheet with semantic selectors and import the utility classes you want:

main {
  @include relative;
  @include flex-col-reverse;
// ...

nav {
...
}

I can't remember the syntax, so treat that as pseudo-css, but you get the idea. From that approach it's not terrible, and it's no longer the equivalent of inline styles, but it still has a bunch of problems. For example, why is there a redundant flex class, when we're also using flex-col-reverse? The latter should include flex as part of its definition anyway.

Unfortunately, that's not hugely different from, you know, writing CSS/Sass. Worse, it's not how anyone does it. As the example from their own website shows, and as innumerable posts here show, what people do in real life is use Tailwind as if it were opinionated inline styles.

I strongly disagree, and think Tailwind - in either use case - is a problem more than a solution, and it's giving us a worse web.

In the CSS-Tricks article about "Atomic CSS" it gives examples like this:

<div class="Bgc(#0280ae) C(#fff) P(20px)">Lorem ipsum</div>

coupled with this:

.Bgc\(#0280ae\) { background-color: #0280ae; }

which I cannot fathom anyone defending.

In the original Challenging CSS Best Practices article referenced there, the author says:

When it comes to CSS, I believe that the sacred principle of “separation of concerns” (SoC) has lead us to accept bloat, obsolescence, redundancy, poor caching and more. Now, I’m convinced that the only way to improve how we author style sheets is by moving away from this principle.

I'm inclined to think that if separating style from content leads to bloat, well, it's not because you're separating those concerns, it's because you're doing the styling wrong. There is, by definition no bloat on the content side, and the style side is up to you to organise. Keeping simple templates and using semantic elements rather than making everything yet another div goes a long way to making it simple.

If the problem is that - as @natescode says, and I know he and I disagree on this :) - regular approaches don't scale that well, then you have to consider the flip side. People add content through WYSIWYG editors, and that pre-marked-up content goes into your data store. In order to change the styling, you either need to do heavy database work, or you need to mark up semantic elements correctly in the first place. For most of us, though, the sort of scale where things get out of hand with CSS is either found in legacy spaghetti-coded sites which have a lot of other problems, or it's a scale we'll rarely need to reach.

Thread

Thread

To each their own. I've worked on fortune 100 and 500 projects. I've seen traditional CSS solutions not scale.

Also, you shouldn't used styled with arbitrary values. The nice thing about utility clases is they limit styles to match designs.

Tailwind can work well. It's just a technology and opinion.

Cheers.

Thread

Thread

Someone said here they can't apply styles to children with tailwind which is way faster, now surprise surprise the newest version of tailwind supports this now.

Thread

Thread

I've never needed it. Flex and grid already affect children and most styles are inheritable anyway.

Thread

Thread

Me too just replying to the guy who is probably still using "float"

Comment button Reply

Nope, all newbs think that. Even I did at first.

  1. Classes can use media queries
  2. Classes limit repeating CSS 3. Classes allow caching stylesheets longer than the HTML that changes more often.
  3. Classes can include multiple properties at once.
  4. Classes support pseudo selectors and pseudo elements etc.
  5. Classes can define keyframes for animation
  6. Sticking to only classes help with specificity issues.
  7. Classes (stylesheets) can be processed with Post-CSS, SASS etc. Which Tailwind generates classes for media queries etc.
  8. Utility classes don't grow your CSS over time. Much easier to maintain. You're not naming, writing and trying to reuse classes made by someone else.
  9. Classes can apply to new HTML in WYSIWYGS.
  10. Utility classes are easier to document and learn. BONUS: editor / lint support. You get autocomplete to find what you need and errors if something is wrong.
  11. Utility classes force sticking to design conventions. I.E. all margin and padding is 8px increments, super easy to configure in Tailwind. One can't use some random color either.

Thread

Thread

1, 3-7: you can do all this using regular CSS without polluting your HTML.
2: I don't understand what you're saying with this one. Yes, you can cache stylesheets - how is that different between Tailwind and normal CSS?
8: Utility classes grow your HTML instead.
9: Do we not care about existing HTML in WYSIWYGs?
10: Something being easier to learn is opinion, not fact. You still need to know what flex-bar-baz does in CSS before using it, except you now have to learn what abbreviation Tailwind decided to go with.
11: Like defining a CSS variable or set of Sass mixins?

Thread

Thread

  1. Yes, but regular CSS doesn't scale. Ever look through a 2MB stylesheet to find a class you need? You end up copy-paste-modify. Mixins helps but can't maintained.

  2. I'm comparing inline styles. Inline styles cache with the HTML not separately as Tailwind classes are defined in a separate stylesheet

  3. Yes, and? Small components keep my HTML clean. You can use variables if you want. I'd rather see all the styles inline then look at yet another file.

  4. Most WYSIWYGs allow for custom classes. And yes, that's an exception. I hate WYSIWYGS. CSS should be HTML agnostic.

  5. Fair enough. More of a rebuttal saying it isn't crazy difficult to learn. It is an abstraction for sure.

  6. Mixins have to be written. Classes are autogenerated.

Variables, yes! I use them WITH Tailwind.

Variables can be hard to name then reuse.

They're not forced like generated classes. There is only bg-myred and color-myred versus I could see someone lazily not looking for the correct variable. Requires more PR review.

Thread

Thread

2: I don't think it's relevant that it's better for caching than inline styles. If we're setting the bar at "better than inline styles" then anything is better, including vanilla CSS; it's not a point in Tailwind's favour.

4: "CSS should be HTML agnostic." If I interpret that literally, it means that you think the styles shouldn't need to have any dependency on the HTML - which is my side of the argument, isn't it?

Thread

Thread

Most say utility classes are no different than inline styles. That's clearly not true. That is my point only.

  1. Depends on how you define it.

I'm done arguing over CSS, it's silly. 😂

Thread

Thread

Yeah, I think you and I aren't going to agree on it, let's come together on another post subject somewhere around something we both like instead :)

Comment button Reply


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK