3. Why Madness?
Because you may become crazy for it.
Or over it.
Or maybe just watching this "Powerpoint" will
drive you insane.
4. Preprocessors
AKA - The "People's Patch"
Our alternative to the cross browser wars.
At least for the time being...
5. Learn CSS and good practices first
Preprocessors are not a replacement for good
coding, planning and design.
6. What is preprocessing?
Preprocessing is essentially creating the
equivalent of a Photoshop file or a suped up
mailing template for your css.
It gives you added umph to your work.
Sometimes making it easier.
Occasionally it might be overkill.
7. Why do it?
Do you like to type the same thing over and over?
Do you enjoy trying to hunt down a tiny bit of code
somewhere in thousands of lines of code and then using
find and replace hoping it'll work?
No?
Use preprocessing.
8. Most of all - DRY practices
Don't Repeat Yourself
9. Other reasons
● CSS 3 browser prefixes
● Responsive design
● Other people are using it, so you want to
have a clue.
● Efficiency
● Better organization
● Faster sites and better SEO
10. Disadvantages
● Learning curve
● Team Maintenance
● Yet another layer
● Code bloat
● Selectoritis
11. Methods and Approaches
● SASS/SCSS
● LESS
● Stylus
● cleverCSS
● cssCrush
● prefixer (http://prefixr.com/)
● force browser to interpret PHP as CSS
12. We're going over the two most
popular preprocessors tonight
LESS and SASS/SCSS
We'll be glossing over some stuff in the interest of time and clarity
14. Let's go over what they share
Each of them now share most of each others
capabilities with some minor differences in
syntax.
The following examples are from Chris
Eppstein's gits on: https://gist.github.
com/674726
Thanks Chris!
15. Variables (placeholders)
Sass | Less
-----------------+-----------------
$color: red; | @color: red;
div { | div {
color: $color; | color: @color;
} | }
Becomes
div { color: #ff0000; }
16. Nesting (outlining)
Sass | Less
-------------------+-----------------
p { | p {
a { | a {
color: red; | color: red;
&:hover { | &:hover {
color: blue; | color: blue; }
} }
} }
Becomes
p a {color: red;}
p a:hover {color: blue;}
25. Differences
As with anything, there are advantages and
disadvantages of going with various options.
LESS and SASS are no different.
Or rather they are in some ways...
26. Extra features of SASS/SCSS
● Can properly "extend" other classes.
● True if, for, while and each control directives
(Logic)
● Global scoping of variables
● Compass (sprites)
● Origin line reporting
● Good Rails integration
● Various output styles
● Real functions that return values
27. Extra features of LESS
● Namespacing
● Guards and Pattern Matching
● Easy compile "on the fly" with a single
JavaScript file.
● Variables as constants
● Twitter Bootstrap
● Usual scope practices
● JavaScript evaluation
28. To compile locally or on the server?
Considerations:
Performance
Coordination
Caching
Server install
31. Hands on part!
Let's do LESS first
Get the example material or use your own
http://files.meetup.com/1962521/basicHtmlCss.zip
Get the basic js
http://lesscss.org - bonus points - download twitter bootstrap
Get a complier
Mac OSX http://incident57.com/less/
Windows http://winless.org/
Linux/Mac/PC http://wearekiss.com/simpless
Get an editor or download the code hinters
http://www.sublimetext.com/
32. Already have the LESS stuff?
To install SASS/SCSS
Go here: http://sass-lang.com/tutorial.html
Download the Windows Installer if you're on Windows.
http://rubyinstaller.org/
After that, go to http://compass-style.org/install/
Follow instructions to install both SASS and Compass
Download either Scout
http://mhs.github.com/scout-app/
Compass app is good too. Just paid.
Configure your editor
I recommend SublimeText along with the Package Installer to install
SCSS/LESS code hinting.
33. "Converting" your existing CSS
Really just nests it.
LEAST
http://toki-woki.net/p/least/
SASS
# Convert Sass to SCSS
$ sass-convert style.css style.scss
34. LESS useful tools if using the js to
compile.
After you put this into your files:
<link rel="stylesheet/less" type="text/css" href="
styles.less">
<script src="less.js" type="text/javascript"
></script>
Put this after your file name in the url:
#!watch
Chrome users: --allow-file-access-from-files in
shortcut or use a local server
mac : terminal ; open /Applications/Google
Chrome.app --args --allow-file-access-from-files
35. Compiling
You can use tools or the command line.
SCSS users may need to delve into their
config.rb file or just use the tools.
LESS users might just want to use the tools to
setup publish paths.
36. Let's have fun with
variables
@myvariable or $myvariable