This talk will break some of the myths regarding pre-processors and explain how they can help you be more efficient coding CSS, by showing examples and practical information about them, available tools, and some useful techniques to get you started and get the most out of them and put you in the right track.
8. Why use preprocessors?
1. CSS is repetitive
2. CSS doesn’t have variables
3. Inflexible, limited reusability
4. Complex websites are hard to maintain
9. The Myths
1.Adds complexity to the development process
2.You lose control over the final code
3.Adds overhead to the website
4.Adds extra dependencies to your workflow
5.Too hard to debug
10. The Myths
God, SCSS looks like
JavaScript and PHP
mated in a drunken state.
Christian Heilmann
13. Myth: Complexity
• Nesting is a natural way of coding
• Named variables are easier to manage than
individual values like colours (E.g.
#0E2740)
• You don’t have to use all the functionality
14. Myth: Lose control
• If your CSS code is currently horrible, your
Sass will undoubtedly be horrible
• Sass doesn’t write code by itself
• Use expanded output option during
development
15. Myth: Overhead
• Compiled file is just plain CSS
• Automatically minify/compress
• Easy to add (or remove) vendor evil
prefixes
• Seamless file concatenation
16. Myth: Dependencies
• Your current set up has many
dependencies
• If you don’t use a pre-processor, you need
a post-processor
• Many tools are available for free, for every
platform
17. Myth: Hard to debug
• Organised code shouldn’t be hard to debug
• There are ways
• It’s getting better
• The cost is low compared to the benefit
23. Debug: —debug-info
• Debug info flag tells you with a comment where
the rule is located in the source file.
• Available only up to Sass 3.2
$ sass --watch —style expanded —debug-info scss:css
Watch a folder
/* _head.scss line: 24 */
.head {
background-color: darkslateblue;
}
Output
24. Debug: Chrome inspector
• Chrome 30+ includes
Sourcemap (Sass 3.3
and Less 1.5+) support
by default
• Stylus considering it
25. Debug: Chrome inspector
• Sourcemaps creates a map of your CSS
• Available only on Sass 3.3+
$ lessc common.less > common.css
Watch the folder
common.css
common.map
Output
26. Debug: File organisation
• Divide and conquer
• Master the
@import rules and
file concatenation
• It’s easier to find a
rule in a small file
public/
assets/
css/
styles.css
img/
js/
scss/
_carousel.scss
_contact.scss
_grid.scss
_home.scss
_typo.scss
styles.scss
27. Tip: File organisation
• Import within media queries so don’t repeat
media queries
@media (max-width: 599px) {
@import “small/base.scss”;
}
• Make one file by component / section with
all its media queries
35. Tip pitch: hoisin.scss
• Light & extensible
• Responsive
• Doesn’t make any design assumptions
• Mobile first, Content first, Performance first
• http://cyber-duck.github.io/hoisin.scss/
36. Which one is the best?
• Sass!
• All have about the same functionality
• Ensure it fits with your workflow
• Compatibility with existing code
• What feels better to you?
37. The Myths
1. Adds complexity to the development process
2. You lose control over the final code
3. Adds overhead to the website
4. Adds extra dependencies to your workflow
5. Too hard to debug
38. Final Considerations
• If you are a CSS beginner
• You need to know how CSS works before
using a pre-processor
• Source Control: ignore compiled / compile on
deployment