SlideShare a Scribd company logo
2
Most read
4
Most read
6
Most read
SASS and SCSS
This document is confidential and contains proprietary information, including trade secrets of CitiusTech. Neither the document nor any of the information
contained in it may be reproduced or disclosed to any unauthorized person under any circumstances without the express written permission of CitiusTech.
Author : Amey Parab
Date of Release :
2
• One of the buzz-words of web design today is CSS-Preprocessors. Many designers and developers are wondering
if they should make the switch over to using a Pre-Processor like SASS instead of just plain CSS.
• Web Applications are getting Bigger and complex today, it’s stylesheets are getting even more complex and
harder to maintain. This is where a pre-processor can help.
• SASS is (Syntactically Awesome Stylesheet) is a CSS pre-processor, which helps to reduce the repetition with CSS
and save time. It is more stable and powerful CSS extension language that describes the style of document
structurally.
• SASS essentially gives lot of the benefits of working with code for stylesheets.
• It has variables, functions and modules that can be imported and re-used. You can iterate, use conditional logic,
extend existing selector styles.
• Best of all, you can nest your CSS. It contains a surprisingly deep feature set but you'll get good value out of just
the half-dozen main features that they advertise on their website.​
• SCSS or Sassy Cascading Style Sheet is the next generation of SASS.
• Both SASS and SCSS are similar and do same thing, but written in different style. SCSS is latest one and considered
better than SASS.​
Introduction of SASS and SCSS
3
Benefits of using SASS/SCSS over traditional CSS
1. Fewer HTTP Requests by using the @import
attribute
2. Keep your responsive design project more organized
3. Reusable Color Scheming
4. Don’t have to repeat similar CSS statements
throughout your project
Pre-requisites
Knowledge of CSS
Knowledge of package managers like Npm
Webpack knowledge will be added advantage
Recipe Description
WorkFlow
CSS vs SASS/SCSS
4
Features of SASS/SCSS
 Fully CSS-compatible
 Many useful functions for manipulating colors and other values:
• Some of the Built-In functions are for Plain CSS, Numbers, Strings, Colors, Lists, Maps, etc.
 Advanced features like control directives for libraries
 Well-formatted, customizable output
 Nesting, Variables
• SASS variable are simple: assign a value to a name begin with $, and then refer to that name instead of a
value itself.
• Variable are most useful tools SASS brings.
• Variable makes it possible to reduce the repetition, do complex math, configure libraries, and much
more.
 Combining CSS files with @import
• Sass imports have the same syntax as CSS imports, except that they allow multiple imports to be
separated by commas.
 Re-using Styles with Mixins
• Mixins allows to define styles that can be re-used throughout stylesheet.
 Extending Styles with Inheritance
5
SASS vs SCSS
 “Sass has two syntaxes. The most commonly used syntax is known as “SCSS” (for “Sassy CSS”), and is a superset
of CSS3’s syntax. This means that every valid CSS3 stylesheet is valid SCSS as well. SCSS files use the extension
.scss.
 The second, older syntax is known as the indented syntax (or just “.sass”). Inspired by Haml’s terseness, it’s
intended for people who prefer conciseness over similarity to CSS. Instead of brackets and semicolons, it uses
the indentation of lines to specify blocks. Files in the indented syntax use the extension .sass.”
 SCSS style is a lot more similar to regular CSS than the older SASS approach. Below is the sample code snippet
/* SASS */
$blue: #3bbfce
$margin: 16px
.content-navigation
border-color: $blue
color: darken($blue, 9%)
.border
padding: $margin / 2
margin: $margin / 2
border-color: $blue
Above code snippet represents SASS approach. It uses line indentations
instead of traditional CSS approach of brackets and semicolons.
/* SCSS */
$blue: #3bbfce;
$margin: 16px;
.content-navigation {
border-color: $blue; color: darken($blue, 9%);
}
.border {
padding: $margin / 2; margin: $margin / 2; border-color: $blue;
}
In the above code snippet we use semi-colon to separate the declarations.
Added all the declarations for .border onto a single line to illustrate this point
further.
6
Steps for Configuration of SCSS with Webpack
Step1: Install sass-loader
npm i sass-loader node-sass webpack --save-
dev
We will also need style-loader and css-loader:
npm i style-loader css-loader --save-dev
Install sass-
loader
Include sass-
loader in your
Webpack config
file
Include the
SASS file in a
container
component
Step 2. Include sass-loader in your
Webpack config file
How It Works:
module: { rules: [{ test: /.scss$/ }] }
Webpack uses a regular expression to
determine which files it should look for
and serve to a specific loader.
In this case any file that ends with .scss
will be served to sass-loader first (sass to
css), then css-loader, and finally style-
loader.
Step 3. Include the SASS file in a
container component
Usually, include the SASS file in the
entry component for your app.
import React from 'react'
import './style.scss'
class App extends React.Component {
render() {
return(<div>Hello World</div>)
}
}
/* Webpack configurations */
module.exports = {
entry: "./app/entry",
output: {
path: path.resolve(__dirname, "dist"),
filename: "bundle.js",
},
module: {
rules: [{
test: /.scss$/,
use: [{
loader: "style-loader"
}, {
loader: "css-loader"
}, {
loader: "sass-loader"
}]
}]
}
7
Mixins
A mixin lets you make groups of CSS declarations that
you want to reuse throughout your site.
You can even pass in values to make your mixin more
flexible.
A good use of a mixin is for vendor prefixes.
To create a mixin:
1. Use the @mixin directive and give it a name.
2. Pass the parameter inside parentheses so that,
reuse of the mixin function can be possible.
3. Use the mixin, as a CSS declaration starting with
@include followed by the name of the mixin.
Here's an example for transform.
/* mixin example */
@mixin transform($property) {
-webkit-transform: $property;
-ms-transform: $property;
transform: $property;
}
.box { @include transform(rotate(30deg)); }
 Doing math in your CSS is very helpful.
 Sass has a handful of standard math operators
like +, -, *, /, and %.
Operators
8
 This is one of the most useful features of Sass.
 Using @extend lets you share a set of CSS
properties from one selector to another.
 It helps keep your Sass very DRY.
 In our example we're going to create a simple
series of messaging for errors, warnings and
successes using another feature which goes hand
in hand with extend, placeholder classes.
 A placeholder class is a special type of class that
only prints when it is extended, and can help keep
your compiled CSS neat and clean.
Extend/Inheritance
/* This CSS will print because %message-shared is extended. */
%common-style {
border: 1px solid #ccc;
padding: 10px;
color: #333;
}
.message {
@extend %common-style ;
}
.success {
@extend %common-style ;
border-color: green;
}
.error {
@extend %common-style ;
border-color: red;
}
9
Advantages and Disadvantages of SCSS
Advantages:
 Sass facilitates you to write clean, easy and less CSS in a programming construct.
 It contains fewer codes so you can write CSS quicker.
 It is more stable, powerful, and elegant because it is an extension of CSS. Hence, it is easy for designers and
developers to work more efficiently and quickly.
 It is compatible with all versions of CSS. So, you can use any available CSS libraries.
 It provides nesting so you can use nested syntax and useful functions like color manipulation, math functions
and other values.
Disadvantages:
 The developer must have enough time to learn new features present in this preprocessor before using it.
 By using preprocessor, you will lose the benefits of browser's built-in element inspector (particularly on
Chrome’s inspector). You have to trace your steps back through the generated CSS.
10
SASS/SCSS Best Practices
While SASS makes your style sheets awesome it doesn't do all the work for you. You'll still have to avoid pitfalls that
will make your SASS more difficult to manage. Here are a few to remember:
 Structure your SASS projects: Use sub folders and partial files to organize code semantically.
 Avoid vague variable names: Use variable names that are meaningful to your project. For example, $color-
primary instead of $blue (this also prepares you in case the colors will change in the future).
 Use nesting and looping to your advantage: It can be very useful to use nesting to visually make your style
sheets easier to read. Looping can help reduce otherwise repetitive code for creating increasing and
decreasing sizes in widths, heights and fonts.
 Keep your @include and @extend statements above the CSS: When you write SASS write any raw CSS below
the @include and @extend statements in the selector.
 Use $kebab-case when naming variables, functions and mixins: Stick with the convention of CSS. CSS doesn't
use camelCase so don't use it in your SASS!
11
Annexure (as needed)
12
Annexure: External References (Library)
 https://sass-lang.com/
 sass Basics
 sass Guide
 partial files
 sass-features
 Frameworks built with Sass:
1. Compass
2. Bourbon
3. Susy
13
Thank You

More Related Content

PPTX
Bliblidotcom - SASS Introduction
PDF
Css preprocessor-140606115334-phpapp01
PDF
CSS preprocessor: why and how
PPT
UNIT 3.ppt
ODP
Deep dive into sass
PPTX
Syntactically awesome stylesheets (Sass)
PDF
Intro to Sass for WordPress Developers
PDF
Atlanta Drupal User's Group - April 2015 - Sasstronauts: Advanced Sass Topics
Bliblidotcom - SASS Introduction
Css preprocessor-140606115334-phpapp01
CSS preprocessor: why and how
UNIT 3.ppt
Deep dive into sass
Syntactically awesome stylesheets (Sass)
Intro to Sass for WordPress Developers
Atlanta Drupal User's Group - April 2015 - Sasstronauts: Advanced Sass Topics

Similar to SCSS Implementation (20)

PDF
Sass that CSS
PPTX
Sass - basic to advance
PDF
Sass conferencia css-sp
PDF
Fasten RWD Development with Sass
ODP
Sass presentation
PDF
DrupalCamp Chattanooga - September 2014 - Sass 101
PPTX
SASS is more than LESS
PPTX
Syntactically Awesome Stylesheet - A workshop by Citytech Software
PDF
Sass and compass workshop
PPTX
Scss talk CSS Meetup
PDF
October 2014 - USG Rock Eagle - Sass 101
PDF
Assembling Sass
PDF
Less vs sass
PDF
PDF
Getting Sassy with CSS
PPTX
Sass:-Syntactically Awesome Stylesheet by Shafeeq
KEY
Future of Sass
PPTX
The sass way - Yatendra Bhardwaj
PPTX
Sass that CSS
Sass - basic to advance
Sass conferencia css-sp
Fasten RWD Development with Sass
Sass presentation
DrupalCamp Chattanooga - September 2014 - Sass 101
SASS is more than LESS
Syntactically Awesome Stylesheet - A workshop by Citytech Software
Sass and compass workshop
Scss talk CSS Meetup
October 2014 - USG Rock Eagle - Sass 101
Assembling Sass
Less vs sass
Getting Sassy with CSS
Sass:-Syntactically Awesome Stylesheet by Shafeeq
Future of Sass
The sass way - Yatendra Bhardwaj
Ad

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Encapsulation theory and applications.pdf
PPTX
Big Data Technologies - Introduction.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Electronic commerce courselecture one. Pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPT
Teaching material agriculture food technology
PPTX
Cloud computing and distributed systems.
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Digital-Transformation-Roadmap-for-Companies.pptx
Encapsulation theory and applications.pdf
Big Data Technologies - Introduction.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Encapsulation_ Review paper, used for researhc scholars
Electronic commerce courselecture one. Pdf
Chapter 3 Spatial Domain Image Processing.pdf
MYSQL Presentation for SQL database connectivity
Building Integrated photovoltaic BIPV_UPV.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
The Rise and Fall of 3GPP – Time for a Sabbatical?
Teaching material agriculture food technology
Cloud computing and distributed systems.
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
“AI and Expert System Decision Support & Business Intelligence Systems”
Mobile App Security Testing_ A Comprehensive Guide.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Ad

SCSS Implementation

  • 1. SASS and SCSS This document is confidential and contains proprietary information, including trade secrets of CitiusTech. Neither the document nor any of the information contained in it may be reproduced or disclosed to any unauthorized person under any circumstances without the express written permission of CitiusTech. Author : Amey Parab Date of Release :
  • 2. 2 • One of the buzz-words of web design today is CSS-Preprocessors. Many designers and developers are wondering if they should make the switch over to using a Pre-Processor like SASS instead of just plain CSS. • Web Applications are getting Bigger and complex today, it’s stylesheets are getting even more complex and harder to maintain. This is where a pre-processor can help. • SASS is (Syntactically Awesome Stylesheet) is a CSS pre-processor, which helps to reduce the repetition with CSS and save time. It is more stable and powerful CSS extension language that describes the style of document structurally. • SASS essentially gives lot of the benefits of working with code for stylesheets. • It has variables, functions and modules that can be imported and re-used. You can iterate, use conditional logic, extend existing selector styles. • Best of all, you can nest your CSS. It contains a surprisingly deep feature set but you'll get good value out of just the half-dozen main features that they advertise on their website.​ • SCSS or Sassy Cascading Style Sheet is the next generation of SASS. • Both SASS and SCSS are similar and do same thing, but written in different style. SCSS is latest one and considered better than SASS.​ Introduction of SASS and SCSS
  • 3. 3 Benefits of using SASS/SCSS over traditional CSS 1. Fewer HTTP Requests by using the @import attribute 2. Keep your responsive design project more organized 3. Reusable Color Scheming 4. Don’t have to repeat similar CSS statements throughout your project Pre-requisites Knowledge of CSS Knowledge of package managers like Npm Webpack knowledge will be added advantage Recipe Description WorkFlow CSS vs SASS/SCSS
  • 4. 4 Features of SASS/SCSS  Fully CSS-compatible  Many useful functions for manipulating colors and other values: • Some of the Built-In functions are for Plain CSS, Numbers, Strings, Colors, Lists, Maps, etc.  Advanced features like control directives for libraries  Well-formatted, customizable output  Nesting, Variables • SASS variable are simple: assign a value to a name begin with $, and then refer to that name instead of a value itself. • Variable are most useful tools SASS brings. • Variable makes it possible to reduce the repetition, do complex math, configure libraries, and much more.  Combining CSS files with @import • Sass imports have the same syntax as CSS imports, except that they allow multiple imports to be separated by commas.  Re-using Styles with Mixins • Mixins allows to define styles that can be re-used throughout stylesheet.  Extending Styles with Inheritance
  • 5. 5 SASS vs SCSS  “Sass has two syntaxes. The most commonly used syntax is known as “SCSS” (for “Sassy CSS”), and is a superset of CSS3’s syntax. This means that every valid CSS3 stylesheet is valid SCSS as well. SCSS files use the extension .scss.  The second, older syntax is known as the indented syntax (or just “.sass”). Inspired by Haml’s terseness, it’s intended for people who prefer conciseness over similarity to CSS. Instead of brackets and semicolons, it uses the indentation of lines to specify blocks. Files in the indented syntax use the extension .sass.”  SCSS style is a lot more similar to regular CSS than the older SASS approach. Below is the sample code snippet /* SASS */ $blue: #3bbfce $margin: 16px .content-navigation border-color: $blue color: darken($blue, 9%) .border padding: $margin / 2 margin: $margin / 2 border-color: $blue Above code snippet represents SASS approach. It uses line indentations instead of traditional CSS approach of brackets and semicolons. /* SCSS */ $blue: #3bbfce; $margin: 16px; .content-navigation { border-color: $blue; color: darken($blue, 9%); } .border { padding: $margin / 2; margin: $margin / 2; border-color: $blue; } In the above code snippet we use semi-colon to separate the declarations. Added all the declarations for .border onto a single line to illustrate this point further.
  • 6. 6 Steps for Configuration of SCSS with Webpack Step1: Install sass-loader npm i sass-loader node-sass webpack --save- dev We will also need style-loader and css-loader: npm i style-loader css-loader --save-dev Install sass- loader Include sass- loader in your Webpack config file Include the SASS file in a container component Step 2. Include sass-loader in your Webpack config file How It Works: module: { rules: [{ test: /.scss$/ }] } Webpack uses a regular expression to determine which files it should look for and serve to a specific loader. In this case any file that ends with .scss will be served to sass-loader first (sass to css), then css-loader, and finally style- loader. Step 3. Include the SASS file in a container component Usually, include the SASS file in the entry component for your app. import React from 'react' import './style.scss' class App extends React.Component { render() { return(<div>Hello World</div>) } } /* Webpack configurations */ module.exports = { entry: "./app/entry", output: { path: path.resolve(__dirname, "dist"), filename: "bundle.js", }, module: { rules: [{ test: /.scss$/, use: [{ loader: "style-loader" }, { loader: "css-loader" }, { loader: "sass-loader" }] }] }
  • 7. 7 Mixins A mixin lets you make groups of CSS declarations that you want to reuse throughout your site. You can even pass in values to make your mixin more flexible. A good use of a mixin is for vendor prefixes. To create a mixin: 1. Use the @mixin directive and give it a name. 2. Pass the parameter inside parentheses so that, reuse of the mixin function can be possible. 3. Use the mixin, as a CSS declaration starting with @include followed by the name of the mixin. Here's an example for transform. /* mixin example */ @mixin transform($property) { -webkit-transform: $property; -ms-transform: $property; transform: $property; } .box { @include transform(rotate(30deg)); }  Doing math in your CSS is very helpful.  Sass has a handful of standard math operators like +, -, *, /, and %. Operators
  • 8. 8  This is one of the most useful features of Sass.  Using @extend lets you share a set of CSS properties from one selector to another.  It helps keep your Sass very DRY.  In our example we're going to create a simple series of messaging for errors, warnings and successes using another feature which goes hand in hand with extend, placeholder classes.  A placeholder class is a special type of class that only prints when it is extended, and can help keep your compiled CSS neat and clean. Extend/Inheritance /* This CSS will print because %message-shared is extended. */ %common-style { border: 1px solid #ccc; padding: 10px; color: #333; } .message { @extend %common-style ; } .success { @extend %common-style ; border-color: green; } .error { @extend %common-style ; border-color: red; }
  • 9. 9 Advantages and Disadvantages of SCSS Advantages:  Sass facilitates you to write clean, easy and less CSS in a programming construct.  It contains fewer codes so you can write CSS quicker.  It is more stable, powerful, and elegant because it is an extension of CSS. Hence, it is easy for designers and developers to work more efficiently and quickly.  It is compatible with all versions of CSS. So, you can use any available CSS libraries.  It provides nesting so you can use nested syntax and useful functions like color manipulation, math functions and other values. Disadvantages:  The developer must have enough time to learn new features present in this preprocessor before using it.  By using preprocessor, you will lose the benefits of browser's built-in element inspector (particularly on Chrome’s inspector). You have to trace your steps back through the generated CSS.
  • 10. 10 SASS/SCSS Best Practices While SASS makes your style sheets awesome it doesn't do all the work for you. You'll still have to avoid pitfalls that will make your SASS more difficult to manage. Here are a few to remember:  Structure your SASS projects: Use sub folders and partial files to organize code semantically.  Avoid vague variable names: Use variable names that are meaningful to your project. For example, $color- primary instead of $blue (this also prepares you in case the colors will change in the future).  Use nesting and looping to your advantage: It can be very useful to use nesting to visually make your style sheets easier to read. Looping can help reduce otherwise repetitive code for creating increasing and decreasing sizes in widths, heights and fonts.  Keep your @include and @extend statements above the CSS: When you write SASS write any raw CSS below the @include and @extend statements in the selector.  Use $kebab-case when naming variables, functions and mixins: Stick with the convention of CSS. CSS doesn't use camelCase so don't use it in your SASS!
  • 12. 12 Annexure: External References (Library)  https://sass-lang.com/  sass Basics  sass Guide  partial files  sass-features  Frameworks built with Sass: 1. Compass 2. Bourbon 3. Susy