SlideShare une entreprise Scribd logo
1  sur  23
Télécharger pour lire hors ligne
BEGIN TO SASS
by Nicha
เหนื่อยไหม?
กับการเขียน CSS แบบเดิมๆ
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;}
น่าเบื่อเนอะ
SASS&Compass
SASS
• CSS variables!
• Mixins
• หาบักง่าย
• เขียน CSS ง่ายขึ้น สั้นขึ้น
Compass
• CSS Frameworks
• มี libraries ให ้
• ใช ้คู่กับ SASS
Install SASS & Compass
Download Ruby ก่อน ที่
http://rubyinstaller.org/downloads/
Install SASS
1.Run > CMD
2.พิมพ์gem install sass
More info: Using SASS http://bit.ly/TZ2Gvv
Install Compass
1. พิมพ์gem install compass
Create Compass Project
1. Go to http://compass-style.org/install/
2. ใส่ path ของโฟลเดอร์ที่เก็บ SASS File และค่าต่างๆ
ตามภาพ
Create Compass Project
1. Copy text ในบรรทัดที่สองไปแปะใน CMD
SASS compile to CSS
SASS
File
CSS file
ที่มีชื่อเหมือนกัน
compile
เช่น style.scss จะถูกแปลงป็น style.css ให้
Using SASS & Compass
ทุกครั้งก่อนเริ่มทํางาน ให้พิมพ์
compass watch [ชื่อโปรเจ็คที่สร้าง] เสมอ
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
Syntax
1. Sassy CSS (SCSS)
2. indented syntax (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
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
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
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
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
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 ชั้น เพื่อความไม่สับสน ***
Properties Nesting
.funky {
font: {
family: fantasy;
size: 30em;
weight: bold;
}
}
SCSS
.funky {
font-family: fantasy;
font-size: 30em;
font-weight: bold;
}
CSS
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 ได ้
ด ้วยการใส่ & ไปข ้างหน้า
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)

Contenu connexe

En vedette

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 

En vedette (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

Begin to sass

  • 3. 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;}
  • 5. SASS&Compass SASS • CSS variables! • Mixins • หาบักง่าย • เขียน CSS ง่ายขึ้น สั้นขึ้น Compass • CSS Frameworks • มี libraries ให ้ • ใช ้คู่กับ SASS
  • 6. Install SASS & Compass Download Ruby ก่อน ที่ http://rubyinstaller.org/downloads/
  • 7. Install SASS 1.Run > CMD 2.พิมพ์gem install sass More info: Using SASS http://bit.ly/TZ2Gvv
  • 9. Create Compass Project 1. Go to http://compass-style.org/install/ 2. ใส่ path ของโฟลเดอร์ที่เก็บ SASS File และค่าต่างๆ ตามภาพ
  • 10. Create Compass Project 1. Copy text ในบรรทัดที่สองไปแปะใน CMD
  • 11. SASS compile to CSS SASS File CSS file ที่มีชื่อเหมือนกัน compile เช่น style.scss จะถูกแปลงป็น style.css ให้
  • 12. Using SASS & Compass ทุกครั้งก่อนเริ่มทํางาน ให้พิมพ์ compass watch [ชื่อโปรเจ็คที่สร้าง] เสมอ
  • 13. 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
  • 14. Syntax 1. Sassy CSS (SCSS) 2. indented syntax (SASS)
  • 15. 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
  • 16. 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
  • 17. 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
  • 18. 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
  • 19. 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
  • 20. 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 ชั้น เพื่อความไม่สับสน ***
  • 21. Properties Nesting .funky { font: { family: fantasy; size: 30em; weight: bold; } } SCSS .funky { font-family: fantasy; font-size: 30em; font-weight: bold; } CSS
  • 22. 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 ได ้ ด ้วยการใส่ & ไปข ้างหน้า
  • 23. 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)