mozilla-frontend-infra / discussions

4 stars 0 forks source link

CSS Direction #1

Open eliperelman opened 7 years ago

eliperelman commented 7 years ago

We don't have any strong direction on CSS patterns and designs, so let's talk about preferences and ideas. Some initial thoughts:

Let the discussion begin :)

eliperelman commented 7 years ago

cc: @helfi92 @darkwing

darkwing commented 7 years ago

I have a hard time with large CSS frameworks because there's always a whole bunch of stuff we don't need or care about. IMO we should create our own basic base CSS file, containing likewise fonts and a standard header we use per project.

helfi92 commented 7 years ago

To write efficient CSS, I think a selector naming guideline would be beneficial. BEM would be a good prospect. Also, if a rule has an ID, there shouldn't be more than one selector or else this might create specificity issues in the future.

eliperelman commented 7 years ago

IMO we should create our own basic base CSS file, containing likewise fonts and a standard header we use per project.

For a good CSS baseline, I think normalize.css is a great start. It's the same one in use by Bootstrap. I totally agree about starting to define some consistency in our UIs. I'd like to see this org also contain a collection of repos that are individual consumable components, in addition to full sites.

I have a hard time with large CSS frameworks because there's always a whole bunch of stuff we don't need or care about.

Not using a monolithic framework is a valid concern. Here are the tradeoffs I see:

Pros

Cons

The first con could probably be mitigated with smarter optimization in Webpack with dead-code elimination, but not sure what work is done there in the CSS realm. @helfi92 is tackling that right now for our build work on neutrino.

To write efficient CSS, I think a selector naming guideline would be beneficial. BEM would be a good prospect.

That's possible; here is a good guide for BEM:

http://bradfrost.com/blog/post/css-architecture-for-design-systems

Also, Tachyons looks really interesting in the minimalist CSS realm that might address some concerns:

http://tachyons.io/

eliperelman commented 7 years ago

Also, if a rule has an ID, there shouldn't be more than one selector or else this might create specificity issues in the future.

I'm usually OK with having selectors with an ID as long as they either describe a single element, or they are used for scoping. Examples:

/* targeting single element */
#element { display: none; }
#element.active { display: block; }

/* scoping */
#header h1 { color: white; }
#main div > a { color: red; }
#footer a { color: grey; }
helfi92 commented 7 years ago

For a good CSS baseline, I think normalize.css is a great start

normalize.css is awesome! We should use it :)

By the way, targeting a single element is definitely okay. My only worry comes with scoping. For example, with

section div .content { 
  background: blue;
}

#footer .content { 
  background: green;
}

the latter will always override the former even though it has fewer selectors. Also, normalize.css does not have rules with ID's. If we start using ID's, we might end up overriding some of those rules by accident.

helfi92 commented 7 years ago

Actually, now that I look more closely, we shouldn't have a problem regarding specificity with normalize.css since they only use a single element in each of their CSS rules.

helfi92 commented 7 years ago

Tachyons looks really interesting in the minimalist CSS realm that might address some concerns

Tachyons is great too. It will definitely make us write less CSS

eliperelman commented 7 years ago

I've been experimenting with https://github.com/threepointone/glamor and it seems pretty logical from a component-based development approach. I know it seems counter-intuitive from a historical standpoint, but for shareable React components, I think it works well for distributing.

eliperelman commented 6 years ago

I've been wanting to try emotion, seems like it works really well and addresses several runtime concerns for CSS-in-JS.