@nzinas
Frontend architect @ bestseller.com
All code in any code-base should look like a single person typed it, no matter how many people contributed
- idiomatic.js
Create your Coding styleguide
No point arguing over these. You just need to pick one and stick to it.
Create your Coding styleguide
.rule-one, .rule-two {
/* Stuff */
}
.rule-one,
.rule-two {
/* Stuff */
}
VS
Create your Coding styleguide
VS
.rule-one {
color: blue; background: red; font-weight: bold;
}
.rule-one {
color: blue;
background: red;
font-weight: bold;
}
Create your Coding styleguide
Create your Coding styleguide
Don't use !important
Don't use inline styles
Don't use ids
Don't use long selectors
(max 3)
Don't overqualify
Create your Coding styleguide
nav .items .item {
/* Bad */
}
nav > .items > .item {
/* Bad */
}
.nav-items {
/* Good */
}
.nav-item {
/* Good */
}
Create your Coding styleguide
but don't be semantic for the sake of semantics
.redText {
border: 1px dotted green;
background: white;
}
Create your Coding styleguide
.js-* works great
Define your methodology
Define your methodology
Separates rules in categories
Define your methodology
Define your methodology
a CSS object is a repeating visual pattern, that can be abstracted into an independent snippet of HTML
Define your methodology
Separate structure and appearance
Container agnostic objects
Define your methodology
Define your methodology
Builds ecosystems
Composes pages out of components
Define your methodology
(Block Element Modifier)
Define your methodology
Block
A reusable component
Element
One piece of the component
Modifier
Different state for a component
or an element
(Block Element Modifier)
Define your methodology
(Block Element Modifier)
/* Block */
.car {}
/* Elements */
.car__door {}
.car__trunk {}
.car__wheel {}
/* Modifiers */
.car--cabrio {}
.car--cabrio .car__trunk {}
.car__wheel--17in {}
.car--cabrio .car__wheel--17in {}
Use a preprocessor
Use a preprocessor
/* Color definitions */
$gray: #333333;
$lightgray: #999999;
/* Base variables */
$headerColor: $gray;
$borderColor: $lightgray;
/* Base styles */
h1, h2, h3, h4, h5, h6 {
color: $headerColor;
}
Use a preprocessor
/* Eliminate vendor prefixes */
.something-with-a-vertical-gradient {
@include background-image(linear-gradient($light-gray, $gray));
}
/* Calculate */
@mixin font-size($font-size, $line-height:true){
font-size:$font-size;
font-size:($font-size / $base-font-size)*1rem;
@if $line-height == true {
line-height:ceil($font-size / $base-line-height)
* ($base-line-height / $font-size);
}
}
.a-block-of-text {
@include font-size(12px);
}
/* Stay DRY */
.container-with-floated-children {
@include clearfix;
}
Use a preprocessor
%btn {
padding: 10px;
border-radius: 5px;
display: inline-block;
cursor: pointer;
text-decoration: none;
}
.btn {
@extend %btn;
color: blue;
background: transparent;
}
.btn--success {
@extend %btn;
color: white;
background: green;
}
.btn--error {
@extend %btn;
color: white;
background: red;
}
Create your styleguide
A living styleguide is a document containing all the modules and components of your application, fully functional and interactive
Create your styleguide
Measure your results
Measure your results
Measure your results
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
@nzinas