DEV Community

Rethinking CSS

Leonora Der on September 29, 2018

I love front-end and back-end. Both the slowly changing, robust back-end technologies and the always-changing front-end frameworks. But when I sa...
Collapse
 
onyeka profile image
Onyeka Aghanenu • Edited

"As like no one would use Vanilla JS nowadays except for beginners"

Bold assumption there.

Anyway, small bits of CSS + OOCSS + Atomic is how I work... especially as I use SCSS imports which comes with partials and this works for me. I split my general CSS into helpers/atomic partials. Layout specific into their own partials, merge it all into one file for production. Then again I don't work at Facebook or Google, so maybe I can't relate to the challenges these massive companies have with CSS.

I see no reason for it to be always-changing. HTML/CSS are the backbone of the web, they need to be stable because unlike JS, every single website needs them. There are small but impactful improvements added to CSS every year, the way improvements are added to decades-old languages like Python or PHP.

If anything I think we should be trying to calm down with the JS framework trends.

Collapse
 
benkressdesign profile image
Ben Kress

I still use vanilla JS after 17 years... Making assumptions that nobody develops without frameworks makes it sound like it is you that is the beginner in this equation. You definitely do not know the collective purpose of developers across the entire web... Making blanket statements that support what you think is not adding value to your viewers. Stick to the facts, and don't push your own beliefs. There is no reason for many developers to use frameworks that aren't as fast or as functional as raw experience. Just because you take the easy way out, which may also be the correct way in your instance... Does not universally mean your way is the only way... And the right way. Let's try to be mature and realize... There are many different opinions and styles of Dev... Keep opinions where they belong.

Collapse
 
leonorader profile image
Leonora Der

With that very first sentence, I meant that there almost no web projects that use no library or framework.

I agree that HTML and CSS need to be stable, and we have the improvements. But as even Python and PHP had its major updates, maybe CSS could have one too! :)

But again, these are just a few random thoughts... :)

Collapse
 
onyeka profile image
Onyeka Aghanenu

I still don't know if it's a good comparison, by nature of how simply CSS is structured and what it's used for, which is styling, you don't really need a framework. I need only 3 lines of CSS to place an element anywhere in a page. I think this is a feature, not a bug.

Even if they did, do things like Bootstrap, Tailwind not count? Or tools like SASS or LESS? They do what something like jQuery does, which is provide shortcuts/pre-written elements so you don't have to.

I don't know, it just feels like a desire to add complexity – trying to make CSS feel like a 'real boy'/language–that it doesn't need.

Collapse
 
aspittel profile image
Ali Spittel

GitHub, Hackernews, and Wikipedia all don't use JavaScript frameworks and many others are only using JQuery for compatibility with old browsers at this point.

Collapse
 
mrjozzi profile image
Joz

So scss then?

Collapse
 
chimon1984 profile image
Ryan Edge

What don't you like about scoped css? Scoped css doesn't necessarily mean you are required to have a file per component, but even if that were required, is it a bad thing to have component css that matches the component driven development of modern libraries?

Collapse
 
leonorader profile image
Leonora Der

I usually use Vue.js so markup, JS and CSS are all in the same template file.

In fact, I like the concept of separation. In my opinion, components are more easily reusable if the design is not included. I mean this way I will be able to make a whole new and consistent design with the same markup and functionality. So even if I can add scoped CSS in Vue templates (and I do for very special CSS rules only), I use global CSS files, too.

But again, I like the concept, and it can be great, but my experience shows that this is something that works for us.

Collapse
 
chimon1984 profile image
Ryan Edge

I can understand that, and I agree we are still figuring it out. In React, I find myself often separating my presentation components from my container components to start and that works 85% of the time. In those cases where I have a lot of styles (atoms), I will break that out into its own file.

I prefer CSSinJS because to me, there's less of a context switch and I haven't ran into a scenario where it didn't meet my needs.

Unfortunately, most of the tooling for this pattern doesn't support the shadow dom, so I find myself using Stencil when I create framework agnostic components.

Collapse
 
pim profile image
Pim

You forgot one of the best, SMACSS. I've employed it with great success for over 5 years. It's used in Yahoo's Pure and my sequel Hydrogen.

Collapse
 
leonorader profile image
Leonora Der

Oh yes... you are right! I love that book and the mindset that comes with it, too! :)

Collapse
 
louislow profile image
Louis Low • Edited

I refactoring my client existing UI so often. And some projects using different types of CSS frameworks. Touching the stylesheet is a true nightmare.

My solution is to keep the existing class names untouched across all the HTML files and refactoring the CSS class property with injecting Yogurt utility modules into something like these:

<div class="title">
  ...
  <div class="desc">
    ...
  </div>
</div>
.title {
  @extend
    .p-2,
    .text-lg, 
    .font-semibold;

    &:hover {
      @extend
        .underline;
    }
}

.desc {
  @extend
    .text-sm, 
    .truncate;
}

Once the refactoring is done with the Yogurt CSS. The next UI development for me will be faster, cleaner, and efficient.

Collapse
 
johncarroll profile image
John Carroll

For a very different take on html page layout, I'd check out Grid Style Sheets. It defines your layout in terms of declarative constraints, which I find to be much more intuitive / readable (not that I've used their library before).

GSS is an implementation of Badros & Borning's Constraint Cascading Style Sheets, enabling far better layout control through building relational rules between different elements.

At this point I think the project's dead, but as long as we're talking about what direction we'd like the web to evolve in, I vote for this direction.

Collapse
 
stevensonmt profile image
stevensonmt

The elm-ui package in the elm language ecosystem is addressing exactly this idea. I love the approach it has taken that means never having to write css again.

Collapse
 
johnkazer profile image
John Kazer • Edited

Elm-ui is no longer maintained?

Collapse
 
stevensonmt profile image
stevensonmt

It is, but it's mdgriffith/elm-ui which used to be style-elements.

Thread Thread
 
johnkazer profile image
John Kazer

thx!