-
Notifications
You must be signed in to change notification settings - Fork 0
CSS Guidelines
- Try not to use ID selectors: they should be used only for JS purpose
- Use dashes instead of camelCasing, underscore or PasalCasing in class names
- Put closing braces } of rule declarations on a new line
- In properties, put a space after, but not before, the : character
- Put blank lines between rule declarations
Bad
.avatar{
border-radius:50%;
border:2px solid white; }
#lol-no {
// ...
}
Good
.avatar{
border-radius: 50%;
border: 2px solid white;
}
Try to use IDs when the element is used in JS. If you must use a class, avoid binding to the same class in both your CSS and JS. You should use JS-specific classes to bind to, prefixed with .js-:
<button class="btn js-request">Request</button>
Put first the box properties (display, width, height...), then the position properties (position, margin...), then the others properties that could have an impact on the element width (such as font-size, font-weight...) and finally everything else.
...
- Prefer line comments (// in Sass-land) to block comments
- Prefer comments on their own line. Avoid end-of-line comments
- Write detailed comments for code that isn't self-documenting (z-index, compatibility or browser-specific hacks...)
Use 0 instead of none to specify that a style has no border.
Bad
.foo {
border: none;
}
Good
.foo{
border: 0;
}
-
List all standard property declarations, anything that isn't an @include or a nested selector, in the order detailed above.
-
Grouping @includes at the end makes it easier to read the entire selector.
-
Nested selectors, if necessary, go last, and nothing goes after them.
.btn { background: green; font-weight: bold; @include transition(background 0.5s ease); .icon { margin-right: 10px; } }