SlideShare ist ein Scribd-Unternehmen logo
1 von 30
Downloaden Sie, um offline zu lesen
0
Introduction to CSS
Preprocessors
Honestly... JustSaSS
by Lucas Torres
Our staff
You can be part of our staff!
inQbation is looking for two great
developers
HTML, CSS and Js lover?You can be our nextFront-end
developer
Enjoycodingin Python, PHP and Drupal?Then the back-end
developer spotcould be yours
About me
Lucas Torres
Web Developer at
inQbation
About me
Python, PHP
HTML, CSS, JavaScript
Drupal
CrazyaboutUX and User Centered Design
Playingwith Node.js and MongoDB
So, aCSS preprocessor receive some instructions and compile
them to .css files
What are CSS Preprocessors?
From Wikipedia:
...apreprocessor is aprogramthatprocesses its
inputdatato produce outputthatis used as
inputto another program.
And what can I do with them?
Have you ever dream aboutusingthe advantages of a
programminglanguage with CSS?Well, that's whatwe are able
to do with CSS preprocessors.
Use variables, functions, mixins, and more.
Which one should I choose?
There are manyCSS Preprocessors
Which one should I choose?
I can'tcompete with more than 1 million results from Google ;)
Which one should I choose?
So, as with beer: Choose the one thattastes better for you
My personal taste is SaSS
AndinbeerisModeloEspecial;)
Main differences: SaSS Vs. Less
SaSS
//Variables
$main_color:#000;
//Nesting
p{
color:$main_color;
a{
text-decoration:underline;
}
}
//Mixins
@mixinshaded-box{
box-shadow:2px2px0px#000;
}
//Functions
@functionsome-function($arg){
@return$arg;
}
Less
//Variables
@main_color:#000;
//Nesting
p{
color:@main_color;
a{
text-decoration:underline;
}
}
//Mixins
.shaded-box{
box-shadow:2px2px0px#000;
}
//Functions
/*404notfound:(*/
SaSS superpowers
Variables
Nesting
Partials &Import
Mixings
Extend/Inheritance
Operators
And yes, functions!
Enough talking man, show me
the code!
Since we don'thave enough time to learn SaSS features from
basics to advanced, I'llshow the coolestones so you can research
deeper later.
Youcangoto tolearnmorehttp://sass-lang.com/documentation
Lets startwith asimple css like this
h1{
font-size:20px;
color:#666;
}
p{
color:#666;
}
.content{
overflow:hidden;
background-color:#F6F6F6;
}
.contenth1{
font-size:18px;
color:#333;
}
.contentp{
font-size:12px;
text-shadow:1px1px0#000;
color:#333;
}
.contentpa{
color:#666;
text-decoration:none;
}
Now, the same code, written in SaSS. Let's begin with variables
//Youcandefinevariables.
//BTW,commentslikethiswon'tcompileinyourCSS
$main_fg_color:#666;
$secondary_fg_color:#333;
h1{
font-size:20px;
color:$main_fg_color;
}
p{
color:$main_fg_color;
}
.content{
overflow:hidden;
background-color:#F6F6F6;
}
.contenth1{
font-size:18px;
color:$secondary_fg_color;
}
.contentp{
font-size:12px;
text-shadow:1px1px0#000;
color:$secondary_fg_color;
}
.contentpa{
color:$main_fg_color;
text-decoration:none;
}
SaSS allows you to use variables, so you can stick to the DRY
principle and keep the code simple and easyto maintain.
Gisthttp://sassmeister.com/gist/9771767
Whataboutnesting?
/*
*Youcannestyourselectors.
*andguesswhat?
*Yes!thiscommentwillbecompiledtoyourCSS
*/
$main_fg_color:#666;
$secondary_fg_color:#333;
h1{
font-size:20px;
color:$main_fg_color;
}
p{
color:$main_fg_color;
}
.content{
overflow:hidden;
background-color:#F6F6F6;
h1{
font-size:18px;
color:$secondary_fg_color;
}
p{
font-size:12px;
text-shadow:1px1px0#000;
color:$secondary_fg_color;
a{
color:$main_fg_color;
text-decoration:none;
}
You can nest selectors, justas in HTML.
Make sense, right?
Gisthttp://sassmeister.com/gist/9771826
Talkingabouteasyto maintain, letme introduce you partials &
import
_text.scss
p{
color:#333;
a{color:#000;text-decoration:none;}
}
main.scss
@import"text";
SaSS won'tcompile anyfile with an underscore atthe beginning
(that's apartial), and the @import directive would import(duh!)
thatfile.
Wantso see some realaction?Ok, let's check the
Mixins
Mixins
Reuse instead of rewrite, thatshould be the definition of Mixins.
//DefinedeMixinproperties
@mixinshaded-box{
-webkit-box-shadow:2px2px0pxrgba(0,0,0,0.75);
-moz-box-shadow: 2px2px0pxrgba(0,0,0,0.75);
box-shadow: 2px2px0pxrgba(0,0,0,0.75);
padding:5px;
}
//ApplytheMixin
.content{
background-color:#F6F6F6;
@includeshaded-box;
}
Gisthttp://sassmeister.com/gist/9772361
Mixins with arguments
Theylook like functions, buttheyare not. (isn'titasuperpower?)
//DefinedeMixinproperties
@mixinshaded-box($blur,$opacity){
-webkit-box-shadow:2px2px$blurrgba(0,0,0,$opacity);
-moz-box-shadow: 2px2px$blurrgba(0,0,0,$opacity);
box-shadow: 2px2px$blurrgba(0,0,0,$opacity);
padding:5px;
}
//ApplytheMixin
.content{
background-color:#F6F6F6;
@includeshaded-box(2px,0.75);
}
Gisthttp://sassmeister.com/gist/9772390
Functions
No more child games!Let's use CSS as aprogramminglanguage
@functionset-background($img:false,$color:#F4F4F4)
{
@if$img!=false{
@return#{$color}url(#{$img})no-repeatlefttop;
}
@else{
@return#{$color};
}
}
.container{
background:set-background("photo.png",#000);
}
Notan usefulfunction, but.. it's afunction inside CSS!
Gisthttp://sassmeister.com/gist/9772407
Control Directives
I betyou saw the @if statementin the lastslide, well, there is
more for you.
//Createaquickgrid
/*Numberofcolumns*/
$columns:12;
@for$ifrom1through$columns{
.col-#{$i}{
width:(100%/$columns)*$i;
float:left;
}
}
You can use @if, @else if, @else, @for, @each and @while
Gisthttp://sassmeister.com/gist/9772438
Control Directives
Now, the same grid butusingafunction
@functionget-col-width($width,$columns,$number){
@return($width/$columns)*$number;
}
$columns:6;
@for$ifrom1through$columns{
.columns-#{$i}{
width:get-col-width(960px,$columns,$i);
@if$i<$columns{
float:left;
}
@else{
float:right;
}
}
}
Gisthttp://sassmeister.com/gist/9772499
Wait! It gets even better!
Reinventingthe wheelis notnice...
You can reuse Compass mixins, functions and more.
Compass
Abrief example with Compass
Gisthttp://sassmeister.com/gist/9773018
And let's proceed with some questions.
Questions?
Thank you!
Introduction to CSS Preprocessors

Weitere ähnliche Inhalte

Ähnlich wie Introduction to CSS Preprocessors

Getting Started with Sass & Compass
Getting Started with Sass & CompassGetting Started with Sass & Compass
Getting Started with Sass & CompassRob Davarnia
 
CSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & CompassCSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & CompassLucien Lee
 
Controlling Web Typography
Controlling Web TypographyControlling Web Typography
Controlling Web TypographyTrent Walton
 
Post css - Getting start with PostCSS
Post css - Getting start with PostCSSPost css - Getting start with PostCSS
Post css - Getting start with PostCSSNeha Sharma
 
Sass & Compass (Barcamp Stuttgart 2012)
Sass & Compass (Barcamp Stuttgart 2012)Sass & Compass (Barcamp Stuttgart 2012)
Sass & Compass (Barcamp Stuttgart 2012)emrox
 
Not Just a Pretty Face: How to design and build a cross-CMS CSS framework
Not Just a Pretty Face: How to design and build a cross-CMS CSS frameworkNot Just a Pretty Face: How to design and build a cross-CMS CSS framework
Not Just a Pretty Face: How to design and build a cross-CMS CSS frameworkcrystalenka
 
Slow kinda sucks
Slow kinda sucksSlow kinda sucks
Slow kinda sucksTim Wright
 
Using SASS in the WordPress environment - Ran Bar Zik
Using SASS in the WordPress environment - Ran Bar ZikUsing SASS in the WordPress environment - Ran Bar Zik
Using SASS in the WordPress environment - Ran Bar ZikMiriam Schwab
 
An Introduction to CSS Preprocessors (SASS & LESS)
An Introduction to CSS Preprocessors (SASS & LESS)An Introduction to CSS Preprocessors (SASS & LESS)
An Introduction to CSS Preprocessors (SASS & LESS)Folio3 Software
 
Revamp Your Stylesheet
Revamp Your StylesheetRevamp Your Stylesheet
Revamp Your StylesheetGary Homidas
 
What is LessCSS and its Detailed Explation - Xhtmlchop
What is LessCSS and its Detailed Explation - XhtmlchopWhat is LessCSS and its Detailed Explation - Xhtmlchop
What is LessCSS and its Detailed Explation - Xhtmlchopxhtmlchop
 
Client side performance compromises worth making
Client side performance compromises worth makingClient side performance compromises worth making
Client side performance compromises worth makingCathy Lill
 
Bliblidotcom - SASS Introduction
Bliblidotcom - SASS IntroductionBliblidotcom - SASS Introduction
Bliblidotcom - SASS IntroductionIrfan Maulana
 

Ähnlich wie Introduction to CSS Preprocessors (20)

PostCss
PostCssPostCss
PostCss
 
Getting Started with Sass & Compass
Getting Started with Sass & CompassGetting Started with Sass & Compass
Getting Started with Sass & Compass
 
CSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & CompassCSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & Compass
 
Controlling Web Typography
Controlling Web TypographyControlling Web Typography
Controlling Web Typography
 
Post css - Getting start with PostCSS
Post css - Getting start with PostCSSPost css - Getting start with PostCSS
Post css - Getting start with PostCSS
 
Sass & Compass (Barcamp Stuttgart 2012)
Sass & Compass (Barcamp Stuttgart 2012)Sass & Compass (Barcamp Stuttgart 2012)
Sass & Compass (Barcamp Stuttgart 2012)
 
Not Just a Pretty Face: How to design and build a cross-CMS CSS framework
Not Just a Pretty Face: How to design and build a cross-CMS CSS frameworkNot Just a Pretty Face: How to design and build a cross-CMS CSS framework
Not Just a Pretty Face: How to design and build a cross-CMS CSS framework
 
Slow kinda sucks
Slow kinda sucksSlow kinda sucks
Slow kinda sucks
 
Using SASS in the WordPress environment - Ran Bar Zik
Using SASS in the WordPress environment - Ran Bar ZikUsing SASS in the WordPress environment - Ran Bar Zik
Using SASS in the WordPress environment - Ran Bar Zik
 
An Introduction to CSS Preprocessors (SASS & LESS)
An Introduction to CSS Preprocessors (SASS & LESS)An Introduction to CSS Preprocessors (SASS & LESS)
An Introduction to CSS Preprocessors (SASS & LESS)
 
Revamp Your Stylesheet
Revamp Your StylesheetRevamp Your Stylesheet
Revamp Your Stylesheet
 
Look ma! No images!
Look ma! No images!Look ma! No images!
Look ma! No images!
 
UNIT 3.ppt
UNIT 3.pptUNIT 3.ppt
UNIT 3.ppt
 
Presentation 1 [autosaved]
Presentation 1 [autosaved]Presentation 1 [autosaved]
Presentation 1 [autosaved]
 
CSS3
CSS3CSS3
CSS3
 
Accelerated Stylesheets
Accelerated StylesheetsAccelerated Stylesheets
Accelerated Stylesheets
 
What is LessCSS and its Detailed Explation - Xhtmlchop
What is LessCSS and its Detailed Explation - XhtmlchopWhat is LessCSS and its Detailed Explation - Xhtmlchop
What is LessCSS and its Detailed Explation - Xhtmlchop
 
Client side performance compromises worth making
Client side performance compromises worth makingClient side performance compromises worth making
Client side performance compromises worth making
 
SASS Preprocessor
SASS PreprocessorSASS Preprocessor
SASS Preprocessor
 
Bliblidotcom - SASS Introduction
Bliblidotcom - SASS IntroductionBliblidotcom - SASS Introduction
Bliblidotcom - SASS Introduction
 

Mehr von Blake Newman

Laravel Restful API and AngularJS
Laravel Restful API and AngularJSLaravel Restful API and AngularJS
Laravel Restful API and AngularJSBlake Newman
 
Software as a Service
Software as a Service Software as a Service
Software as a Service Blake Newman
 
Git and the inQbation Experience
Git and the inQbation ExperienceGit and the inQbation Experience
Git and the inQbation ExperienceBlake Newman
 
How to migrate content to Drupal using XML files
How to migrate content to Drupal using XML filesHow to migrate content to Drupal using XML files
How to migrate content to Drupal using XML filesBlake Newman
 
inQbation - Washington DC Web Agency
inQbation - Washington DC Web AgencyinQbation - Washington DC Web Agency
inQbation - Washington DC Web AgencyBlake Newman
 

Mehr von Blake Newman (8)

Laravel Restful API and AngularJS
Laravel Restful API and AngularJSLaravel Restful API and AngularJS
Laravel Restful API and AngularJS
 
Chrome DevTools
Chrome DevToolsChrome DevTools
Chrome DevTools
 
Software as a Service
Software as a Service Software as a Service
Software as a Service
 
SEO Workshop
SEO WorkshopSEO Workshop
SEO Workshop
 
Git and the inQbation Experience
Git and the inQbation ExperienceGit and the inQbation Experience
Git and the inQbation Experience
 
How to migrate content to Drupal using XML files
How to migrate content to Drupal using XML filesHow to migrate content to Drupal using XML files
How to migrate content to Drupal using XML files
 
inQbation - Washington DC Web Agency
inQbation - Washington DC Web AgencyinQbation - Washington DC Web Agency
inQbation - Washington DC Web Agency
 
Elements of SEO
Elements of SEOElements of SEO
Elements of SEO
 

Kürzlich hochgeladen

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

Kürzlich hochgeladen (20)

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

Introduction to CSS Preprocessors

  • 1. 0
  • 4. You can be part of our staff! inQbation is looking for two great developers HTML, CSS and Js lover?You can be our nextFront-end developer Enjoycodingin Python, PHP and Drupal?Then the back-end developer spotcould be yours
  • 5. About me Lucas Torres Web Developer at inQbation
  • 6. About me Python, PHP HTML, CSS, JavaScript Drupal CrazyaboutUX and User Centered Design Playingwith Node.js and MongoDB
  • 7. So, aCSS preprocessor receive some instructions and compile them to .css files What are CSS Preprocessors? From Wikipedia: ...apreprocessor is aprogramthatprocesses its inputdatato produce outputthatis used as inputto another program.
  • 8. And what can I do with them? Have you ever dream aboutusingthe advantages of a programminglanguage with CSS?Well, that's whatwe are able to do with CSS preprocessors. Use variables, functions, mixins, and more.
  • 9. Which one should I choose? There are manyCSS Preprocessors
  • 10. Which one should I choose? I can'tcompete with more than 1 million results from Google ;)
  • 11. Which one should I choose? So, as with beer: Choose the one thattastes better for you
  • 12. My personal taste is SaSS AndinbeerisModeloEspecial;)
  • 13. Main differences: SaSS Vs. Less SaSS //Variables $main_color:#000; //Nesting p{ color:$main_color; a{ text-decoration:underline; } } //Mixins @mixinshaded-box{ box-shadow:2px2px0px#000; } //Functions @functionsome-function($arg){ @return$arg; } Less //Variables @main_color:#000; //Nesting p{ color:@main_color; a{ text-decoration:underline; } } //Mixins .shaded-box{ box-shadow:2px2px0px#000; } //Functions /*404notfound:(*/
  • 15. Enough talking man, show me the code! Since we don'thave enough time to learn SaSS features from basics to advanced, I'llshow the coolestones so you can research deeper later. Youcangoto tolearnmorehttp://sass-lang.com/documentation
  • 16. Lets startwith asimple css like this h1{ font-size:20px; color:#666; } p{ color:#666; } .content{ overflow:hidden; background-color:#F6F6F6; } .contenth1{ font-size:18px; color:#333; } .contentp{ font-size:12px; text-shadow:1px1px0#000; color:#333; } .contentpa{ color:#666; text-decoration:none; }
  • 17. Now, the same code, written in SaSS. Let's begin with variables //Youcandefinevariables. //BTW,commentslikethiswon'tcompileinyourCSS $main_fg_color:#666; $secondary_fg_color:#333; h1{ font-size:20px; color:$main_fg_color; } p{ color:$main_fg_color; } .content{ overflow:hidden; background-color:#F6F6F6; } .contenth1{ font-size:18px; color:$secondary_fg_color; } .contentp{ font-size:12px; text-shadow:1px1px0#000; color:$secondary_fg_color; } .contentpa{ color:$main_fg_color; text-decoration:none; } SaSS allows you to use variables, so you can stick to the DRY principle and keep the code simple and easyto maintain. Gisthttp://sassmeister.com/gist/9771767
  • 19. Talkingabouteasyto maintain, letme introduce you partials & import _text.scss p{ color:#333; a{color:#000;text-decoration:none;} } main.scss @import"text"; SaSS won'tcompile anyfile with an underscore atthe beginning (that's apartial), and the @import directive would import(duh!) thatfile.
  • 20. Wantso see some realaction?Ok, let's check the Mixins
  • 21. Mixins Reuse instead of rewrite, thatshould be the definition of Mixins. //DefinedeMixinproperties @mixinshaded-box{ -webkit-box-shadow:2px2px0pxrgba(0,0,0,0.75); -moz-box-shadow: 2px2px0pxrgba(0,0,0,0.75); box-shadow: 2px2px0pxrgba(0,0,0,0.75); padding:5px; } //ApplytheMixin .content{ background-color:#F6F6F6; @includeshaded-box; } Gisthttp://sassmeister.com/gist/9772361
  • 22. Mixins with arguments Theylook like functions, buttheyare not. (isn'titasuperpower?) //DefinedeMixinproperties @mixinshaded-box($blur,$opacity){ -webkit-box-shadow:2px2px$blurrgba(0,0,0,$opacity); -moz-box-shadow: 2px2px$blurrgba(0,0,0,$opacity); box-shadow: 2px2px$blurrgba(0,0,0,$opacity); padding:5px; } //ApplytheMixin .content{ background-color:#F6F6F6; @includeshaded-box(2px,0.75); } Gisthttp://sassmeister.com/gist/9772390
  • 23. Functions No more child games!Let's use CSS as aprogramminglanguage @functionset-background($img:false,$color:#F4F4F4) { @if$img!=false{ @return#{$color}url(#{$img})no-repeatlefttop; } @else{ @return#{$color}; } } .container{ background:set-background("photo.png",#000); } Notan usefulfunction, but.. it's afunction inside CSS! Gisthttp://sassmeister.com/gist/9772407
  • 24. Control Directives I betyou saw the @if statementin the lastslide, well, there is more for you. //Createaquickgrid /*Numberofcolumns*/ $columns:12; @for$ifrom1through$columns{ .col-#{$i}{ width:(100%/$columns)*$i; float:left; } } You can use @if, @else if, @else, @for, @each and @while Gisthttp://sassmeister.com/gist/9772438
  • 25. Control Directives Now, the same grid butusingafunction @functionget-col-width($width,$columns,$number){ @return($width/$columns)*$number; } $columns:6; @for$ifrom1through$columns{ .columns-#{$i}{ width:get-col-width(960px,$columns,$i); @if$i<$columns{ float:left; } @else{ float:right; } } } Gisthttp://sassmeister.com/gist/9772499
  • 26. Wait! It gets even better! Reinventingthe wheelis notnice... You can reuse Compass mixins, functions and more.
  • 27. Compass Abrief example with Compass Gisthttp://sassmeister.com/gist/9773018 And let's proceed with some questions.