Giter Club home page Giter Club logo

css-guidelines's Introduction

CSS Guidelines

Principles

  • Consistency
  • Maintainability
  • Readability
  • Scalability

Tools

PostCSS details coming soon

Architecture

Folder Structure

We prefix our directories with the number associated with the order in which it's imported in my main styles.css file.

css/
|
| -- 0_vendor/
| -- 1_settings/
| -- 2_base/
| -- 3_components/
| -- 4_layout/
| -- 5_helpers/
| -- 6_overrides/

Vendor

0_vendor includes any third party CSS that can't be imported via npm.

Settings

1_settings is a place to store global variables, mixins, etc. that don't directly compile into CSS.

Base

2_base is where classless element selectors are given some basic styles.

Components

3_components includes all of our repeatable patterns, or components. Component classes are prefixed with c-.

Layout

4_layout includes styles for more structural elements like page layouts and grids. Layout classes are prefixed with l-.

Helpers

5_helpers is where "helper" classes are defined. Helper classes are prefixed with h- and include an !important rule.

Overrides

6_overrides - Override vendor styles, write hacky CSS due to framework limitations, etc.

File Names

The main file, styles.css, looks something like this:

/* ==========================================================================
 * Styles
 * ========================================================================== */

/* Vendor */
@import "normalize.css";
@import "0_vendor/...";

/* Settings */
@import "1_settings/...";

/* Base */
@import "2_base/...";

/* Components */
@import "3_components/...";

/* Layout */
@import "4_layout/...";

/* Helpers */
@import "5_helpers/...";

/* Overrides */
@import "6_overrides/...";

Naming Conventions

Namespacing

We use the following namespacing:

Type Prefix Example
Components c- c-button
c-card
Layout Modules l- l-container
l-grid
Helpers h- h-clearfix
States is-
has-
is-active
has-loaded
JavaScript Hooks js- js-accordion

BEM

We use the BEM naming convention:

.block { ... }
.block__element { ... }
.block--modifier { ... }
.block__element--modifier { ... }

BEM Do's and Don'ts

  • Don't use a modifier outside of the context of its owner.
๐Ÿ‘Ž DON'T
<button class="c-button--large"></button>
๐Ÿ‘ DO
<button class="c-button c-button--large"></button>
  • Don't combine multiple BEM entities on a single DOM node.
๐Ÿ‘Ž DON'T
<button class="c-button c-icon">...</button>
๐Ÿ‘ DO
<button class="c-button">
  <span class="c-icon">...</span>
</button>

Order

Declaration Order

Coming Soon

Nesting Order

Use the following order for nesting selectors:

.card {
  /* CSS Variables */
  /* Note: Not fully supported as of 8/1/2016 http://caniuse.com/#feat=css-variables */
  --color: #fff;
  
  /* Applies and Mixins */
  @apply --example;
  @mixin --something;
  
  /* Declaration List */
  display: block;
  ...
  z-index: 1;

  /* Media Queries */
  @media screen and (min-width: 900px) {
    ...
  }

  /* Pseudo States */
  &:hover {
    ...
  }

  /* Pseudo Elements */
  &::before,
  &::after {
    ...
  }

  &:nth-child(odd) {
    ...
  }

  /* Modifiers */
  &--small {
    ...
  }

  /* Concatenated Selectors */
  &.is-active {

  }

  /* Nested Elements */
  &__body {
    ...
  }
  
  /* Nested Selectors */
  .label {
    ...
  }
}

Linting

Credits / Inspiration

css-guidelines's People

Contributors

jonmilner avatar

Stargazers

Julia Donaldson avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.