Skip to content

Instantly share code, notes, and snippets.

@jasperkennis
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasperkennis/4071e8a3d5fee5c61799 to your computer and use it in GitHub Desktop.
Save jasperkennis/4071e8a3d5fee5c61799 to your computer and use it in GitHub Desktop.
Homerun CSS Rules

Purpose of this document:

Our CSS is a mess and needs to improve. Let's have some rules for that.

Style classes not elements

Our habit to style elements makes it easy to swap elements without affecting style.

Generalise styles

We need buttons everywhere and they are more or less the same. So use a single class button and add as many modifiers (additional classes) as nesesarry for all small exceptions.

More classes is better

Need a paragraph with a special margin and a special color? Make two modifiers; one for the margin and one for the color.

Nest as little as possible

Nesting leads to large selectors, especially if high up the selector change there is a comma in a selector.

Do not change existing styles unless you know exactly where they apply

If at all posible and reasonable, define an additional class. If possible and reasonable, make the class generic; if you need to add some extra margin to some object, make that a generic extra margin class, don't apply it to just one single element. This makes the class much more reusable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment