All Projects → grvcoelho → Css Styleguide

grvcoelho / Css Styleguide

Licence: mit
📖 Opinionated CSS styleguide for scalable applications

Projects that are alternatives of or similar to Css Styleguide

google-java-style-guide-zh cn
📖【译】Google Java 编程风格指南
Stars: ✭ 70 (-82.23%)
Mutual labels:  styleguide
Bee Stylish
🕶 Styleguides da moda (ou não)
Stars: ✭ 286 (-27.41%)
Mutual labels:  styleguide
Css Style Guide Audit
Audit the CSS on a page to see what elements are using styles from the style guide and which styles are overriding them
Stars: ✭ 353 (-10.41%)
Mutual labels:  styleguide
nuxt-styleguide
Increase the quality and efficiency of product design and development workflows
Stars: ✭ 15 (-96.19%)
Mutual labels:  styleguide
Javascript Style Guide
Guía de Estilo para programar con JavaScript, en español. Apoyo es bienvenido :)
Stars: ✭ 278 (-29.44%)
Mutual labels:  styleguide
Elements Of Python Style
Goes beyond PEP8 to discuss what makes Python code feel great. A Strunk & White for Python.
Stars: ✭ 3,308 (+739.59%)
Mutual labels:  styleguide
flake8-cognitive-complexity
An extension for flake8 that validates cognitive functions complexity
Stars: ✭ 44 (-88.83%)
Mutual labels:  styleguide
Elixir style guide
This is community style guide for the Elixir programming language. Please feel free to make pull requests and suggestions, and be a part of Elixir's vibrant community.
Stars: ✭ 3,870 (+882.23%)
Mutual labels:  styleguide
Overview
中文编程的历史、现状和展望。issue 中进行相关问题的讨论.
Stars: ✭ 282 (-28.43%)
Mutual labels:  styleguide
Uiengine
Workbench for UI-driven development
Stars: ✭ 349 (-11.42%)
Mutual labels:  styleguide
Vuejs Component Style Guide
Vue.js Component Style Guide
Stars: ✭ 2,796 (+609.64%)
Mutual labels:  styleguide
Deno Manual Cn
Deno 中文手册
Stars: ✭ 278 (-29.44%)
Mutual labels:  styleguide
Api Guidelines
Microsoft REST API Guidelines
Stars: ✭ 17,897 (+4442.39%)
Mutual labels:  styleguide
learningHub
Style guides and learning materials for devs, to build lightning-fast web apps 🚀 | HTML | CSS | JS | REACT
Stars: ✭ 19 (-95.18%)
Mutual labels:  styleguide
Clojure Style Guide
A community coding style guide for the Clojure programming language
Stars: ✭ 3,740 (+849.24%)
Mutual labels:  styleguide
sass-common
Common Sass mixins and files
Stars: ✭ 13 (-96.7%)
Mutual labels:  styleguide
To Title Case
A JavaScript method for intelligently converting strings to title case.
Stars: ✭ 306 (-22.34%)
Mutual labels:  styleguide
Story2sketch
Convert Storybook into Sketch symbols 💎
Stars: ✭ 391 (-0.76%)
Mutual labels:  styleguide
Django Api Domains
A pragmatic styleguide for Django API Projects
Stars: ✭ 365 (-7.36%)
Mutual labels:  styleguide
Ios Handbook
Guidelines and best practices for excellent iOS apps
Stars: ✭ 337 (-14.47%)
Mutual labels:  styleguide

css

Opinionated CSS styleguide for scalable applications

This guide was heavily inspired by experiments, awesome people like @fat and @necolas and awesome projects made by Google, Airbnb and Medium.

Table of Contents

  1. Terminology 1. Rule Declaration 1. Selectors 1. Properties
  2. [Formatting] (#formatting) 1. [Spacing] (#spacing) 1. [Nesting] (#nesting) 1. [Quotes] (#quotes) 1. [Comments] (#comments)
  3. [Syntax] (#syntax) 1. [Components] (#components) 1. [Descendants] (#descendants) 1. [Modifiers] (#modifiers) 1. [States] (#states)

Terminology

The following are some terms used throughout this styleguide.

Rule declaration

A “rule declaration” is the name given to a selector (or a group of selectors) with an accompanying group of properties. Here's an example:

.avatar {
  font-size: 18px;
  line-height: 1.2;
}

Selectors

In a rule declaration, “selectors” are the bits that determine which elements in the DOM tree will be styled by the defined properties. Selectors can match HTML elements, as well as an element's class, ID, or any of its attributes. Here are some examples of selectors:

.avatar {
  font-size: 20px;
}

#id {
  font-size: 20px;
}

Properties

Finally, properties are what give the selected elements of a rule declaration their style. Properties are key-value pairs, and a rule declaration can contain one or more property declarations. Property declarations look like this:

.avatar {
  background: rgb(255,255,255);
  color: rgb(33,33,33);
}

Formatting

The following are some high level page formatting style rules.

Spacing

CSS rules should be comma separated and leave on a new line:

/* wrong */
.avatar, .tweet {

}
/* right */
.avatar, 
.tweet {

}

Properties should use a space after : but not before:

/* wrong */
.avatar {
  font-size : 12px;
}

.tweet {
  font-size:12px;
}
/* right */
.avatar {
  font-size: 12px;
}

Rule declarations should have one property per line:

/* wrong */
.avatar {
  font-size: 12px; letter-spacing: 2px;
}
/* right */
.avatar {
  font-size: 12px; 
  letter-spacing: 2px;
}

Declaration should be separated by two new lines:

/* wrong */
.avatar {
  font-size: 12px;
}
.tweet {
  letter-spacing: 2px;
}
/* right */
.avatar {
  font-size: 12px;
}

.tweet {
  letter-spacing: 2px;
}

Nesting

Do not nest elements. Keep nesting to pseudo-classes and direct interactions with the parent element. Although nesting is a powerful feature provided by several preprocessors and plugins, it can easily get out of control and generate a terrible css ouput with high specificity or spoil the code legibility.

/* wrong */
.avatar {
  font-size: 12px;
  
  &:hover {
    font-size: 11px;
  }
  
  &__link {
    color: rgb(210,210,22);
  }

  &__photo {
    height: 20px;
  }
}
/* right */
.avatar {
  font-size: 12px;
  
  &:hover {
    font-size: 11px;
  }
}

.avatar__link {
  color: rgb(210,22,221);
}

.avatar__photo {
  height: 20px;
}

Nesting can also be used to when an element is dependent of a parent's modifier. This helps to keep all code related to an element on the same block.

.avatar {
  font-size: 12px;
}

.avatar__photo {
  height: 20px;
  
  .avatar--big & {
    height: 40px;
  }
}

Quotes

Quotes are optional in CSS. You should use single quotes as it is visually clearer that the string is not a selector or a style property.

/* wrong */
.avatar {
  background-image: url(/img/you.jpg);
  font-family: Helvetica Neue Light, Helvetica Neue, Helvetica, Arial;
}
/* right */
.avatar {
  background-image: url('/img/you.jpg');
  font-family: 'Helvetica Neue Light', 'Helvetica Neue', Helvetica, Arial;
}

Comments

Avoid comments as hard as you can. Comments are not easily mantainable and are usually used to supress application design mistakes. Leave comments only to things that are really not straightforward such as browser-specific hacks. Put comments on their own lines to describe content below them.

/* wrong */
.avatar {
  height: 200px; /* this is the height of the container*/
  background-color: rgb(221,33,21); /* brand color */
}
/* right */
.avatar {
  height: 20px;
  
  /* this is a hack to fix click behavior on Safari 6.0 */
  pointer-events: none;
}

Syntax

Syntax: <component-name>[--modifier-name|__descendant-name]

Component driven development offers several benefits when reading and writing HTML and CSS:

  • It helps to distinguish between the classes for the root of the component, descendant elements, and modifications.
  • It keeps the specificity of selectors low.
  • It helps to decouple presentation semantics from document semantics.

You can think of components as custom elements that enclose specific semantics, styling, and behaviour.

Components

Syntax: component-name

The component's name must be written in kebab case.

.my-component {
  font-size: 20px;
}
<article class="my-component"></article>

Descendants

Syntax: component-name__descendant-name

A component descendant is a class that is attached to a descendant node of a component. It's responsible for applying presentation directly to the descendant on behalf of a particular component. Descendant names must be written in kebab case.

<article class="tweet">
  <header class="tweet__header">
    <img class="tweet__avatar" src="{$src}" alt="{$alt}"></header>
  <div class="tweet__body"></div>
</article>

Modifiers

Syntax: component-name--modifier-name

A component modifier is a class that modifies the presentation of the base component in some form. Modifier names must be written in kebab case and be separated from the component name by two hyphens. The class should be included in the HTML in addition to the base component class.

.btn {
  padding: 20px 10px;
}

.btn--primary { 
  background: rgb(148,146,231);
}
<button class="btn btn--primary"></button>

States

Syntax: component-name.is-state-of-component

Use is-stateName for state-based modifications of components. The state name must be kebab case. Never style these classes directly; they should always be used as an adjoining class.

JS can add/remove these classes. This means that the same state names can be used in multiple contexts, but every component must define its own styles for the state (as they are scoped to the component).

.tweet { 
  height: 90px;
}

.tweet.is-expanded { 
  height: 200px;
}
<article class="tweet is-expanded"></article>

License

MIT © 2016

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].