Which is the best way to present CSS?
Both of the following divs are identical, but I have seen both methods of applying CSS. Most people seem to teach the former, but the likes of Amazon and Facebook use the latter. Just wondering if there are any advantages to either. Maybe admin could create a poll to see which is most popular 😄
7 Replies
this kind of code is for tailwind
at the very least the arguments for or against are the same as for tailwind
tailwind didn't invent utility classes
of course, not to mention it's how Bootstrap works too
but bootstrap is very different from tailwind
I feel like method 2 with all the utility classes, especially if they're all single-line ones, kinda defeats the point of using css in the first place
or rather, defeats the purpose of not just using inline styles
it leads to ugly class definitions, and if you use them to make say a card, and you want to change that card down the line, now you have to find where you used it in half a dozen places instead of just changing your
card-whatever
class and being done
it works better for some people if you're using a component based framework, but then if you have one of those it probably supports scoped CSS anyway, so why not just write out your rules like normal?
It's personal preference at the end of the day though, it doesn't matter a tonUtility classes are great when you want to repeat the same settings multiple times, or to be able to change lots of things at once from one spot. But making everything 100% like taht would be a pain in the ass, and you would be better off just using tailwind at that point
I was just wondering if there were any advantages, like, often I have set rules for a div, but then used it later and changed couple of things - do these crossed out previous settings take up valuable time and resources?