begin to sass

23
BEGIN TO SASS by Nicha

Upload: nicha-jutasirivongse

Post on 06-Jul-2015

334 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Begin to sass

BEGIN TO SASSby Nicha

Page 2: Begin to sass

เหนอยไหม?

กบการเขยน CSS แบบเดมๆ

Page 3: Begin to sass

ul{ list-style: none;}ul li{ padding: 10px 5px; }ul li span{ color: red; font-size: 12px;}

ul li a{ color: black;}ul li a:hover{ color: gray;}ul li a:active{ color: blue;}

Page 4: Begin to sass

นาเบอเนอะ

Page 5: Begin to sass

SASS & Compass

SASS• CSS variables!• Mixins• หาบกงาย • เขยน CSS งายขน สนขน

Compass• CSS Frameworks• ม libraries ให • ใชคกบ SASS

Page 6: Begin to sass

Install SASS & Compass

Download Ruby กอน ท

http://rubyinstaller.org/downloads/

Page 7: Begin to sass

Install SASS

1.Run > CMD

2.พมพ gem install sass

More info: Using SASS http://bit.ly/TZ2Gvv

Page 8: Begin to sass

Install Compass

1. พมพ gem install compass

Page 9: Begin to sass

Create Compass Project1. Go to http://compass-style.org/install/

2. ใส path ของโฟลเดอรทเกบ SASS File และคาตางๆ ตามภาพ

Page 10: Begin to sass

Create Compass Project

1. Copy text ในบรรทดทสองไปแปะใน CMD

Page 11: Begin to sass

SASS compile to CSS

SASSFile

CSS fileทมชอเหมอนกน

compile

เชน style.scss จะถกแปลงปน style.css ให

Page 12: Begin to sass

Using SASS & Compass

ทกครงกอนเรมทางาน ใหพมพ

compass watch [ชอโปรเจคทสราง] เสมอ

Page 13: Begin to sass

SASS Features• Fully CSS3-compatible• Language extensions such as variables, nesting, and

mixins• Many useful function for manipulating colors and other

values• Advanced features like control directives for libraries• Well-formatted, customizable output• Firebug Intregration (add ons)

More info: • Sass useful functions : http://bit.ly/SLqe3o• Sass control directives: http://bit.ly/RWKFeQ• Firefox Add ons : http://bit.ly/QctKZ4

Page 14: Begin to sass

Syntax

1. Sassy CSS (SCSS)2. indented syntax (SASS)

Page 15: Begin to sass

SCSS Syntax

•Similar to CSS•An extension of the syntax of CSS3•Understand most of CSS hacks and vendor-specific syntax

•*.scss format

More info: http://bit.ly/SLpk7b

Page 16: Begin to sass

SASS Syntax

•Indented syntax (like python)• Use indentation rather than brackets to indicate nesting of selectors

• Use newlines rather than semicolons to separate properties

•Easier to read and Faster to write•*.sass format

More info: http://bit.ly/SLpk7b

Page 17: Begin to sass

Converting SASS and SCSS

สามารถแปลงไฟล .scss เปน .sass ไดงายๆ โดยพมพ

คาสงใน command line

# Convert Sass to SCSS sass-convert style.sass style.scss

# Convert SCSS to Sass sass-convert style.scss style.sass

Page 18: Begin to sass

Writing SCSS• Comments• Nesting• Properties Nesting• Parent Reference Selectors• Variable• Interpolation• Operations and Functions• Mixin

• Mixin with argument• Mixin control (if, else if, for, while)

• @import

Page 19: Begin to sass

Comments

/* This comment is * several lines long. * since it uses the CSS

comment syntax, * it will appear in the CSS

output. */

body { color: black; }

// These comments are only one line long each. // They won't appear in the CSS output, // since they use the single-line comment syntax.

a { color: green; }

SCSS/* This comment is* several lines long.* since it uses the CSS

comment syntax,* it will appear in the CSS

output. */

body {color: black;

}a {

color: green; }

CSS

Page 20: Begin to sass

Nesting

#main p { color: #0f0; width: 97%; .redbox { background-color: #f00; color: #000;

}}

SCSS#main p { color: #0f0; width: 97%;

}#main p .redbox { background-color: #f00; color: #000;

}

CSS

*** ไมควร Nested เกน 3 ชน เพอความไมสบสน ***

Page 21: Begin to sass

Properties Nesting

.funky { font: { family: fantasy; size: 30em; weight: bold;

} }

SCSS.funky {font-family: fantasy;font-size: 30em;font-weight: bold;

}

CSS

Page 22: Begin to sass

Parent Reference Selectors

#main { color: black; a { font-weight: bold;&:hover { color: red;

} }

}

SCSS#main { color: black;

}#main a { font-weight: bold;

}#main a:hover { color: red;

}

CSS

เราสามารถ Reference ตว parent selectors ได ดวยการใส & ไปขางหนา

Page 23: Begin to sass

Variable

$main-color: #ce4dd6;$style: solid;

#navbar {border-bottom: {

color: $main-color;style: $style;

}}a {

color: $main-color;}

SCSS#navbar {

border-bottom-color: #ce4dd6;

border-bottom-style: solid; }

a {color: #ce4dd6;

}

CSSเราประกาศตวแปรดวย $ (เหมอน php)