SlideShare a Scribd company logo
1 of 19
Download to read offline
A Practical
Introduction To Sass
by Sanjay Poyzer

Hello everybody, I’m going to be doing a practical introduction to Sass, the CSS Preprocessor.
http://sassnotsass.com

First things first, it’s Sass not SASS. Sass doesn’t stand for anything, except maybe making your CSS more Sassy…?
Sass makes CSS more Sassy because it’s a preprocessor. Preprocessors make writing code easier. 

!

If it helps, you can think of Sass making CSS more like a real programming language. If that doesn’t help, just think of it as a way to write CSS that’s more
cleverer. 

!

On that note, those of you who do program may find this a bit slow, but I want to make sure people who just know CSS get some of the concepts that Sass
relies on.
Browsers Don’t Know
Sass
heyyyy!

Who are you?

Everything you know about browsers still stands though. They don’t know Sass, so you need to convert what you write with Sass back over to CSS at some
point before your page loads. That sounds like a pain, and it actually put me off for ages, but it’s actually super simple to do. I’ll leave that bit to the end
though.
Sass is like LESS.
But it’s better.
Here’s why
- http://css-tricks.com/sass-vs-less/

I’m not going to talk too much about LESS in this talk. LESS serves a similar function, it’s a preprocessor, but most people these days tend to agree Sass is
better. If you’re really interested in why, the effable Chris Coyier has done a write up in detail.
Reasons We
1. Variables	

2. Mixins	

3. Nesting	


4. Partials /
Imports	

5. Extends	

6. Operators

So what can we actually do with Sass? Well, at a glance, these are it’s main features. Let’s dive into them one by one.
.sass

.scss

.css

Before we do that though, here’s some Sass. It might look a bit scary and weird right now, but hopefully by the end of this it will make complete sense.
You’ll notice there are 2 ways to write Sass. Proper Sass and “Sassy CSS”, or .scss. The only difference is that if you go full Sass, you don’t need to write
those curly brackets, it’s syntax is recognised through indentations. That’s cool and everything, but I tend to stick with .scss, mainly because all normal
CSS is already valid in a .scss file. So I can start a project in CSS, and then decide that actually Sass is going to be useful here, and just copy the code over
to a .scss file. Also I kind of find those curly brackets oddly comforting…
.scss

.css

1. Variables
So here’s feature #1 - Variables. Variables are a staple of programming in general, but absent from CSS, which is a shame. Especially because there are so
many things in your stylesheets that could change at any time. An easy practical example is setting up colors, or fonts as variables. Let’s say you were
writing just in CSS and then you wanted to change your site’s colour scheme. You’ve probably used the same colours a bunch of times throughout your
site, so it would be a pain to go through and change them all. Ok sure, you *could* find and replace. But this way is cooler.
Sass keeps you DRY

That’s the biggest selling point of Sass. It helps keep you DRY. DRY stands for Don’t Repeat Yourself. It’s good programming practice, and the idea is if
you start repeating yourself anywhere, think about if when change instance 1, you also want the second instance to change. In CSS, you can think about
that all you want and nothing’s going to change but in Sass you can make those things a Variable. But that’s not all…
.scss

.css

2. Mixins
You can also give those variables arguments. Mixins are basically variables that can take arguments. Again, the programmers in the room will know what’s
going on here but for everyone else, the brackets are essentially an extra input to the function. So you set up your mixin and say when this is called,
output all of this stuff, and every time this happens, replace it with whatever’s in the brackets. It’s pretty powerful for those CSS3 features that need vendor
prefixes. It’s best to have a bunch of these mixins set up for all the times you need to tell CSS to do a bunch of stuff, but with a variable in the middle of it.
You might already use a CSS framework like Bootstrap. Sass frameworks (Compass is a great one) mostly use the power of mixins to make all this stuff
easier to write.
.scss

.css

3. Nesting
But not as cool as this. This might be my personal favourite thing that Sass does. It might not be immediately obvious from these examples, but nesting
will save you a bunch of typing time. In the example on the left, you’ll see we only needed to type ‘nav’ once.
.scss

HTML

3. Nesting
It also saves you thinking time. If you’re anything like me, you’ll spend a lot of time looking at websites using the Element Inspector on the right. Nesting
allows you to structure your CSS to reflect the DOM tree laid out in HTML. It’s still the same CSS eventually remember, it’s just easier to read for purpose.
However…
Think carefully about specificity.

After this, go watch Harry Roberts’ talk on Big CSS.
http://youtu.be/R-BX4N8egEc

Sass won’t solve all your problems for you though. Think carefully about how specific you want each rule to be. It’s best to try and keep your CSS rules as
broad as possible, to apply to the most amount of elements with the least amount of work. So go watch Harry Roberts’ talk on Big CSS. It’s an hour of your
time, but really will change the way you write CSS, whether or not you choose to use a preprocessor like Sass.
Coming back to Sass, a general rule of thumb with nesting to avoid being over specific is “Don’t nest more than twice.” If you’re nesting more than that,
have a think about if there’s actually any purpose to it. Going back to the menu example, you can see it doesn’t completely reflect the HTML, because it
doesn’t really need to in this case.
+

4. Partials / Imports
Sass does Partials and Imports way better than normal CSS. In normal CSS, you can break your stylesheets up into smaller, more manageable files and use
@import to compile them. However, that compiling happens all on the client side. Each HTTP request slows down the overall speed of your site, but
because Sass is processed before it gets anywhere near the browser, you can break your stylesheets up as many times as you want, and it will get compiled
into one handy stylesheet.
.scss

.css

5. Extends
Extends are pretty simple to understand. Take all the rules applied to this class, and apply them to this class as well. 
If you take yourself through the process of writing the CSS on the right, you’ll see that you just wouldn’t think to write it like that. What you’d probably end
up doing is writing all those rules for those classes individually, which would be boring to write and just be extra code for the computer to process.
Also…

Extends help you stay semantic.

After this, go read “Bootstrap without all the debt”
https://coderwall.com/p/wixovg

Extends are a really great way to keep your HTML semantic. Instead of littering your HTML with tonnes of classes like “main-font green big” that could
potentially change later on, you can keep all your style rules in your stylesheets! Bootstrap and other bits of copied code gets people into bad practices like
this, mainly because out of context, you kind of need those classes in your HTML. But when you’re working on a big site that might be changed a fair bit,
you can use extends to keep everything cleaner.
.scss

.css

6. Operators (+, -, *, / & %)
Sometimes maths is useful when you’re writing stylesheets. There’s actually now a calc function in normal CSS that acts fairly similar, but that relies on
browser support. Using operators in Sass is of course especially powerful because you can use variables like $sidebar-width and then calculate a margin
that you know will change when you change that variable. You can also do if functions, and for and while loops. I won’t go into those here though.
You. Writing code.
Preprocessing, e.g. CoffeScript,
Server-Side, e.g. PHP/Ruby
Client-Side, e.g. HTML, CSS, JS

The User.
When you’re doing maths though, or indeed any computation in your code - You need to be mindful of where in the process between you and the user that
computation is happening; Where your code runs. So without preprocessors in the mix, you have your front end and your back end; Your server side stuff
and your client side. That’s why you can’t use maths in Sass to respond to a user resizing their window for instance, and you can’t set up variables in Sass
that change depending on something the user does. It compiles over here, way before any of that stuff happens.
You can make your client-side stuff talk to your server side, but you can never get that stuff to talk to preprocessors, because Browsers don’t know Sass.
How to preprocessor?
Using ‘Rails? Get the gem.

So by now you’re probably all dying to know how do I actually turn this Sass stuff into CSS that the browser can understand. Well, if you’re using Ruby on
Rails, you just install the gem and you don’t need to worry about it ever again. If not, you’ll either have to tell your computer via the command line to
watch for changes in the file you’re working on and then compile it.. OR just install a program that does that for you. Here’s some examples. I personally
use CodeKit for Mac, and Jerome uses Prepros on his PC. It’s really simple, you just add your project and make sure your app is running while you work.
This list is taken from the Sass website, which brings me onto my final slide…
http://sass-lang.com

The Sass website. More information about everything I’ve talked about is on there in the docs, including reference for all the terms. When you start using
Sass, you’ll probably need it open in a tab for a bit, but there really isn’t that much to learn and I promise you it will make your life better!

More Related Content

Recently uploaded

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
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 

Recently uploaded (20)

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
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

Featured

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
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellSaba Software
 

Featured (20)

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
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 

Introduction To Sass

  • 1. A Practical Introduction To Sass by Sanjay Poyzer Hello everybody, I’m going to be doing a practical introduction to Sass, the CSS Preprocessor.
  • 2. http://sassnotsass.com First things first, it’s Sass not SASS. Sass doesn’t stand for anything, except maybe making your CSS more Sassy…? Sass makes CSS more Sassy because it’s a preprocessor. Preprocessors make writing code easier. ! If it helps, you can think of Sass making CSS more like a real programming language. If that doesn’t help, just think of it as a way to write CSS that’s more cleverer. ! On that note, those of you who do program may find this a bit slow, but I want to make sure people who just know CSS get some of the concepts that Sass relies on.
  • 3. Browsers Don’t Know Sass heyyyy! Who are you? Everything you know about browsers still stands though. They don’t know Sass, so you need to convert what you write with Sass back over to CSS at some point before your page loads. That sounds like a pain, and it actually put me off for ages, but it’s actually super simple to do. I’ll leave that bit to the end though.
  • 4. Sass is like LESS. But it’s better. Here’s why - http://css-tricks.com/sass-vs-less/ I’m not going to talk too much about LESS in this talk. LESS serves a similar function, it’s a preprocessor, but most people these days tend to agree Sass is better. If you’re really interested in why, the effable Chris Coyier has done a write up in detail.
  • 5. Reasons We 1. Variables 2. Mixins 3. Nesting 4. Partials / Imports 5. Extends 6. Operators So what can we actually do with Sass? Well, at a glance, these are it’s main features. Let’s dive into them one by one.
  • 6. .sass .scss .css Before we do that though, here’s some Sass. It might look a bit scary and weird right now, but hopefully by the end of this it will make complete sense. You’ll notice there are 2 ways to write Sass. Proper Sass and “Sassy CSS”, or .scss. The only difference is that if you go full Sass, you don’t need to write those curly brackets, it’s syntax is recognised through indentations. That’s cool and everything, but I tend to stick with .scss, mainly because all normal CSS is already valid in a .scss file. So I can start a project in CSS, and then decide that actually Sass is going to be useful here, and just copy the code over to a .scss file. Also I kind of find those curly brackets oddly comforting…
  • 7. .scss .css 1. Variables So here’s feature #1 - Variables. Variables are a staple of programming in general, but absent from CSS, which is a shame. Especially because there are so many things in your stylesheets that could change at any time. An easy practical example is setting up colors, or fonts as variables. Let’s say you were writing just in CSS and then you wanted to change your site’s colour scheme. You’ve probably used the same colours a bunch of times throughout your site, so it would be a pain to go through and change them all. Ok sure, you *could* find and replace. But this way is cooler.
  • 8. Sass keeps you DRY That’s the biggest selling point of Sass. It helps keep you DRY. DRY stands for Don’t Repeat Yourself. It’s good programming practice, and the idea is if you start repeating yourself anywhere, think about if when change instance 1, you also want the second instance to change. In CSS, you can think about that all you want and nothing’s going to change but in Sass you can make those things a Variable. But that’s not all…
  • 9. .scss .css 2. Mixins You can also give those variables arguments. Mixins are basically variables that can take arguments. Again, the programmers in the room will know what’s going on here but for everyone else, the brackets are essentially an extra input to the function. So you set up your mixin and say when this is called, output all of this stuff, and every time this happens, replace it with whatever’s in the brackets. It’s pretty powerful for those CSS3 features that need vendor prefixes. It’s best to have a bunch of these mixins set up for all the times you need to tell CSS to do a bunch of stuff, but with a variable in the middle of it. You might already use a CSS framework like Bootstrap. Sass frameworks (Compass is a great one) mostly use the power of mixins to make all this stuff easier to write.
  • 10. .scss .css 3. Nesting But not as cool as this. This might be my personal favourite thing that Sass does. It might not be immediately obvious from these examples, but nesting will save you a bunch of typing time. In the example on the left, you’ll see we only needed to type ‘nav’ once.
  • 11. .scss HTML 3. Nesting It also saves you thinking time. If you’re anything like me, you’ll spend a lot of time looking at websites using the Element Inspector on the right. Nesting allows you to structure your CSS to reflect the DOM tree laid out in HTML. It’s still the same CSS eventually remember, it’s just easier to read for purpose.
  • 12. However… Think carefully about specificity. After this, go watch Harry Roberts’ talk on Big CSS. http://youtu.be/R-BX4N8egEc Sass won’t solve all your problems for you though. Think carefully about how specific you want each rule to be. It’s best to try and keep your CSS rules as broad as possible, to apply to the most amount of elements with the least amount of work. So go watch Harry Roberts’ talk on Big CSS. It’s an hour of your time, but really will change the way you write CSS, whether or not you choose to use a preprocessor like Sass. Coming back to Sass, a general rule of thumb with nesting to avoid being over specific is “Don’t nest more than twice.” If you’re nesting more than that, have a think about if there’s actually any purpose to it. Going back to the menu example, you can see it doesn’t completely reflect the HTML, because it doesn’t really need to in this case.
  • 13. + 4. Partials / Imports Sass does Partials and Imports way better than normal CSS. In normal CSS, you can break your stylesheets up into smaller, more manageable files and use @import to compile them. However, that compiling happens all on the client side. Each HTTP request slows down the overall speed of your site, but because Sass is processed before it gets anywhere near the browser, you can break your stylesheets up as many times as you want, and it will get compiled into one handy stylesheet.
  • 14. .scss .css 5. Extends Extends are pretty simple to understand. Take all the rules applied to this class, and apply them to this class as well. If you take yourself through the process of writing the CSS on the right, you’ll see that you just wouldn’t think to write it like that. What you’d probably end up doing is writing all those rules for those classes individually, which would be boring to write and just be extra code for the computer to process.
  • 15. Also… Extends help you stay semantic. After this, go read “Bootstrap without all the debt” https://coderwall.com/p/wixovg Extends are a really great way to keep your HTML semantic. Instead of littering your HTML with tonnes of classes like “main-font green big” that could potentially change later on, you can keep all your style rules in your stylesheets! Bootstrap and other bits of copied code gets people into bad practices like this, mainly because out of context, you kind of need those classes in your HTML. But when you’re working on a big site that might be changed a fair bit, you can use extends to keep everything cleaner.
  • 16. .scss .css 6. Operators (+, -, *, / & %) Sometimes maths is useful when you’re writing stylesheets. There’s actually now a calc function in normal CSS that acts fairly similar, but that relies on browser support. Using operators in Sass is of course especially powerful because you can use variables like $sidebar-width and then calculate a margin that you know will change when you change that variable. You can also do if functions, and for and while loops. I won’t go into those here though.
  • 17. You. Writing code. Preprocessing, e.g. CoffeScript, Server-Side, e.g. PHP/Ruby Client-Side, e.g. HTML, CSS, JS The User. When you’re doing maths though, or indeed any computation in your code - You need to be mindful of where in the process between you and the user that computation is happening; Where your code runs. So without preprocessors in the mix, you have your front end and your back end; Your server side stuff and your client side. That’s why you can’t use maths in Sass to respond to a user resizing their window for instance, and you can’t set up variables in Sass that change depending on something the user does. It compiles over here, way before any of that stuff happens. You can make your client-side stuff talk to your server side, but you can never get that stuff to talk to preprocessors, because Browsers don’t know Sass.
  • 18. How to preprocessor? Using ‘Rails? Get the gem. So by now you’re probably all dying to know how do I actually turn this Sass stuff into CSS that the browser can understand. Well, if you’re using Ruby on Rails, you just install the gem and you don’t need to worry about it ever again. If not, you’ll either have to tell your computer via the command line to watch for changes in the file you’re working on and then compile it.. OR just install a program that does that for you. Here’s some examples. I personally use CodeKit for Mac, and Jerome uses Prepros on his PC. It’s really simple, you just add your project and make sure your app is running while you work. This list is taken from the Sass website, which brings me onto my final slide…
  • 19. http://sass-lang.com The Sass website. More information about everything I’ve talked about is on there in the docs, including reference for all the terms. When you start using Sass, you’ll probably need it open in a tab for a bit, but there really isn’t that much to learn and I promise you it will make your life better!