less & sass

25
LESS & Sass Overview

Upload: -

Post on 05-Dec-2014

3.029 views

Category:

Education


0 download

DESCRIPTION

Basic overview of tho popular css preprocesors

TRANSCRIPT

Page 1: Less & Sass

LESS & Sass Overview

Page 2: Less & Sass

How to START with

Page 3: Less & Sass

Client-side way

Download less.js

http://lesscss.org/

Create style.less file

Instead of style.css

Page 4: Less & Sass

<link rel="stylesheet/less" href="styles.less" />

<script src="less.js" ></script>

Link both files with the main HTML doc

Page 5: Less & Sass

Server-side way

First possibility

Download NPM https://github.com/isaacs/npm

Or get Node.js

http://nodejs.org/

Second possibility

Download Ruby http://www.ruby-lang.org/en/downloads

For Windows users

http://rubyinstaller.org

Now start the command prompt

Page 6: Less & Sass

$ npm install -g less

If you chose NPM type:

Page 7: Less & Sass

$ gem install less

If you chose Ruby type:

Page 8: Less & Sass

How to compile the Less code?

Client-side way It happens automatically when you hit (F5).

You could also use some compilation tools.

Server-side way $ lessc style.less > style.css

Less compiler

Less file

Output Css file

Page 9: Less & Sass

LESS Compilers

Remember the client-side way, well this is pretty much the same, but we have tools to help us.

simpLess LiveReload CodeKit

Page 10: Less & Sass

How to START with

Page 11: Less & Sass

Just Server-side way (there are dome unofficial client side ways)

$ gem install sass

Page 12: Less & Sass

How to compile the Sass code?

Server-side way $ sass --watch style.scss : style.css

Sass compiler

Watch for compilation

CSS code file SASS code file

Page 13: Less & Sass

Less & Sass comparison

Page 14: Less & Sass

Variables just a value container

Page 15: Less & Sass

Sometimes we repeat the same value over and over

#firstElement {

background: #abcdef

}

#secondElement {

background : #abcdef

}

#thirdElement {

color : #ff91aa;

}

...

#nthElement {

color : #ff91aa;

}

color : #ff91aa

background: #abcdef

Page 16: Less & Sass

LESS

@bgColor : #abcdef;

@justColor : #ff91aa;

#firstElement{

background: @bgColor;

}

$bgColor : #abcdef;

$justColor : #ff91aa;

#firstElement{

background: $bgColor;

}

SASS

Page 17: Less & Sass

Mixins variables on steroids

Page 18: Less & Sass

Sometimes we repeat a big chinks of code with different values over and over

#justElement {

-moz-bordee-radius: 10px;

-webkit-border-radius: 10px;

-o-border-radius: 10px;

border-radius: 10px;

}

#anotherElement {

/* if we want the same*/

}

Page 19: Less & Sass

LESS

.roundBorder( @val : 10px ) {

-moz-bordee-radius: @val;

-webkit-border-radius: @val;

-o-border-radius: @val;

border-radius: @val;

}

#justElement{

.roundBorder( );

}

#anatherElement{

.roundBorder(17px);

}

@roundBorder( $val : 10x) {

-moz-bordee-radius: $val;

-webkit-border-radius: $val;

-o-border-radius: $val;

border-radius: $val;

}

#justElement{

@include roundBorder()

}

#anotherElement{

@include roundBorder(17px)

}

SASS

Page 20: Less & Sass

Nested css code no more epic repetition code

Page 21: Less & Sass

If we have a lot of nested content is tedious to have address the deepest elements

<div id=“main”>

<p>

<span>Span text</span>

<a href=“#”>Link</a>

</p>

</div>

#main {

width:500px

}

#main p {

width: 150px;

}

#main p span {

color: #abcdef;

}

#main p a {

text-decoration: none;

}

Page 22: Less & Sass

LESS and SaSS

#main{

width: 500px;

p {

width: 150px;

span {

color: #abcdef;

}

a {

text-decoration: none;

}

}

}

FIRST LEVEL NESTING (P ELEMENT)

SECOND LEVEL NESTING Span element

SECOND LEVEL NESTING anchor element

Page 23: Less & Sass

Functions & Operations a way to do the math

Page 24: Less & Sass

Operations

LESS example // width variable

@width: 500px;

#divNewWidth {

width: (@width + 10)

}

Sass example

// width variable

$width : 500px;

#divNewWidth {

width: ($width + 10);

}

Both Sass and Less supports math operators(+|-|*|/|%).

Page 25: Less & Sass

Functions

Sass functions:

http://sasslang.com/docs/yardoc/Sass/Script/Functions.html

Less functions: http://lesscss.org/#-color-functions

Both Sass and Less supports a variety of Math and Color functions, that generated specific css values