Graduate Your Stylesheet Strategy
CSS forethought
= painful to maintain CSS
Few iterations later we had a stylesheet strategy
Keep appending to the bottom
Where do we go from here?
/** DO NOT EVER CHANGE THIS! **/
SMACSS
Organizational system
- Base
- Layout
- Module
- State
- Theme
minified + distributed 2 files
core.css
fonts, grids and header/footer
application.css
page specific styles + non core components
CSS lines = 0 && styling inconsistent
default "system" stylesheet
syntactic sugar
variables, functions(mixins), conditionals and loops
Preprocessors
It is a CSS language extension
preproccessed language -> CSS
human readable VS machine readable
SASS .sass + .scss
.SCSS
$primary-color: #333;
body { color: $primary-color; }
.SASS
primary-color: #333
body
color: $primary-color
SASS maintainability ++
@mixin respond-to($breakpoint)
@media only screen and (min-width : #{$breakpoint}px)
@content
.nav
width: 100%
+respond-to(600)
width: 50px
float: left
.box{
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
.box
border-radius: 5px
border-radius examplemixins, js solutions, postprocessing
Autoprefixer
decorates/augments CSS with prefixes
issue with ad-hoc
long selector chains
incorrect specificity
Need methodology
A methodology tells us how to do stuff
BEM methodology
object oriented design ideas
Block, Element, Modifier
Naming convention
Block, Element, Modifier
.site-nav {} /* Block */
.site-nav__field {} /* Element */
.site-nav__field--full {} /* Modifier */
Semantics
Adds meaning to selectors
.person__hand--left {}
Meaning
.js-widget
.is-hidden
agree on using class selectors
selector types
#widget { } /* id */
.widget { } /* class */
widget { } /* element */
Using classes will aid Specificity
Specificity determines which CSS rule is applied by the browsers.
Don't use a grenade to dig a hole when a shovel will do
added bonus - Selector performance
parsed right to left
rightmost is the key selector
.nav .nav__block--left {
font-weight: bold;
}
practical CSS challenges
- Achitecture
- Syntactic Sugar
- CSS concepts
- BEM Methodology
not a list of browsers + versions
cutting the mustard
QuerySelector, Local Storage, ClassList, AddEventListener
:) Browsers
full experience
:( Browsers
no svg icons, no CSS3 effects, no custom fonts
self documenting code doesn't cut it
BUT.... it's a pain and it's first to go out of date :(
// [doc] Vertically center content.
// Use this class on the container and
// __inner on the element to be centered.
// [/doc]
.vertically-centered
Style strategy materialized = Rizzo
consistent UI look and feel
style resource for designers + third parties
live representation of our front end
Summary
- Ad-hoc style crafting
- Arhcitecture SMACSS
- Bundle and minify
- Resets
- Preprocessors
- Postprocessor
- BEM naming convention
- Browser support
- Documentation
- Live Styleguide Rizzo