SlideShare a Scribd company logo
1 of 11
Download to read offline
From the Resource Library of Andolasoft.Inc | Web and Mobile App Development Company 1
From the Resource Library of Andolasoft.Inc | Web and Mobile App Development Company 2
How To Organize And Structure Your SASS Code
SASS (Syntactically awesome style sheets) is an extension of the CSS which adds syntactic
power to the basic CSS language making it easier for developers to write CSS. It is just a CSS
preprocessor, so that you can write CSS in an easy and convenient way.
“Sass is a meta-language on top of CSS that's used to describe the style of a document cleanly
and structurally, with more power than flat CSS allows. Sass both provides a simpler, more
elegant syntax for CSS and implements various features that are useful for creating manageable
style sheets.”
“Sass is an extension of CSS3, adding nested rules, Variables, mixins, selector inheritance, and
more. It’s translated to well-formatted, standard CSS using the command line tool or a web-
framework plugin.”
It’s Sass not SASS. Sass doesn’t stand for anything, except maybe making your CSS Sassier. Sass
makes CSS more Sassy because it’s a preprocessor. Preprocessors make writing code easier.
If it helps you 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 cleverer.
TheHistory of SASS:
▪ Sass was first given life by Hampton Catlin in 2006, later supported by Natalie
weizembaum and ChrisEpstein
▪ Sass started life in ruby community
▪ Sass supports two syntaxes
–Indentation syntax with file ext .sass
–CSS compatible syntax with file ext .scss
▪ Sass is free to use, require no license.
Why Use SASS?
▪ Modularize (@import)
▪ Variables for maintainability
▪ Mixins improves reusability
▪ Reduces redundant rules (keep it DRY)
From the Resource Library of Andolasoft.Inc | Web and Mobile App Development Company 3
▪ Scalable and Maintainable
▪ Sass is completely compatible with all versions of CSS
▪ Sass reduces repetition of CSS and therefore saves time
▪ It provides the document style in a good, structured format, better than vanilla CSS
▪ It uses re-usable methods, logic statements and some of the built-in functions such as
color manipulation, mathematics and parameter lists
SASS and SCSS
Two available syntaxes
SASS
▪ HAML-style indentation
▪ No brackets or semi-colons, based on indentation
▪ Less characters to type
▪ Enforced conventions/neatness
SCSS
▪ Semi-colon and bracket syntax
▪ Superset of normal CSS
▪ Normal CSS is also valid SCSS
▪ Newer and recommended
How toInstall SASS on Computer
Install Live SASS Compiler Extension in VS Code
▪ Select the Extensions tab from the sidebar. Click on the Extensions tab from the sidebar
▪ Search for Live Server in the search box
▪ Search for “Live Sass Compiler” from the search box
▪ Click on the Install button
▪ It is now in NodeJS package also
▪ First install NodeJS
From the Resource Library of Andolasoft.Inc | Web and Mobile App Development Company 4
▪ then Enter NPM install –g sass
The SASS File structure pattern
sass/
|
|– abstracts/ (or utilities/)
| |– _variables.scss // Sass Variables
| |– _functions.scss // Sass Functions
| |– _mixins.scss // Sass Mixins
|
|– base/
| |– _reset.scss // Reset/normalize
| |– _typography.scss // Typography rules
|
|– components/ (or modules/)
| |– _buttons.scss // Buttons
| |– _carousel.scss // Carousel
| |– _slider.scss // Slider
|
|– layout/
| |– _navigation.scss // Navigation
| |– _grid.scss // Grid system
| |– _header.scss // Header
| |– _footer.scss // Footer
| |– _sidebar.scss // Sidebar
| |– _forms.scss // Forms
|
|– pages/
| |– _home.scss // Home specific styles
| |– _about.scss // About specific styles
| |– _contact.scss // Contact specific styles
|
|– themes/
| |– _theme.scss // Default theme
| |– _admin.scss // Admin theme
|
|– vendors/
| |– _bootstrap.scss // Bootstrap
| |– _jquery-ui.scss // jQuery UI
|
`– main.scss // Main Sass file
From the Resource Library of Andolasoft.Inc | Web and Mobile App Development Company 5
@import 'abstracts/variables';
@import 'abstracts/functions';
@import 'abstracts/mixins';
@import 'vendors/bootstrap';
@import 'vendors/jquery-ui';
@import 'base/reset';
@import 'base/typography';
@import 'layout/navigation';
@import 'layout/grid';
@import 'layout/header';
@import 'layout/footer';
@import 'layout/sidebar';
@import 'layout/forms';
@import 'components/buttons';
@import 'components/carousel';
@import 'components/slider';
@import 'pages/home';
@import 'pages/about';
@import 'pages/contact';
@import 'themes/theme';
@import 'themes/admin';
▪ Our folders would typically contain the following like abstracts contains tools, helpers,
variables, mixins etc.
▪ Base contains boilerplate code for the project. This includes styles such as resets,
typography etc.
▪ Components contains all the smaller page components like separated into multiple
smaller files like slider, carousel etc.
▪ Layout contains the layout styles, separated into several smaller files like header, footer
etc.
▪ Pages contains page-specific styles. For example, the home page and search results page
typically looks very different.
▪ Themes contains files that are theme specific, like alternate color schemes (if any).
From the Resource Library of Andolasoft.Inc | Web and Mobile App Development Company 6
▪ Vendors contains third party code from external frameworks and libraries like jQueryUi,
Bootstrap etc.
▪ Our main file is only used to import all the other files.
Reasons We Love SASS
Variables
▪ Sass allows to declare variables that can be used throughout the style sheet
▪ Variables begin with $ and are declared like properties
They can have any value that’s allowed for a CSS property, such as colors, numbers, or
text
Variables: SASS vs. SCSS
From the Resource Library of Andolasoft.Inc | Web and Mobile App Development Company 7
Mixins
Mixins allow to re-use whole chunks of CSS, properties or selectors
Mixins are defined using the “@mixin” directive, which takes a block of styles that can
then be included in another selector using the “@include” directive
Mixins: SASS vs. SCSS
From the Resource Library of Andolasoft.Inc | Web and Mobile App Development Company 8
Nesting
▪ Often in CSS there are several selectors that begin in the same way
▪ Sass avoids repetition by nesting selectors within one another
Properties can be nested too
▪ Pseudo classes can be nested too (e.g. :hover)
▪ Sass special character &in a selector & is replaced with the parent selector
From the Resource Library of Andolasoft.Inc | Web and Mobile App Development Company 9
Nesting: SASS vs. SCSS
From the Resource Library of Andolasoft.Inc | Web and Mobile App Development Company 10
Imports
Style sheets can be big: the @import directive that allows to break styles up into multiple style
sheets
Operator and functions
▪ Sass supports basic math operations and many useful functions
▪ http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html
▪ The standard math
• Operations(+, -, *, /, and %) are supported for numbers
There are many useful functions for colors, e.g. To change lightness, hue, saturation,
From the Resource Library of Andolasoft.Inc | Web and Mobile App Development Company 11
Selector inheritance
Sass can tell one selector to inherit all the styles of another without duplicating the CSS
properties
Conclusion:
Organizing code is essential for developers and together with all other skills.It is the most
effective way to improve the functioning of the site. And even though there are multiple ways
of organization and different strategies, opting for simplicity helps you avoid the dangerous
pitfalls. And finally, there is no right or wrong choice since everything depends on the
developer’s work strategies.

More Related Content

More from Andolasoft Inc

14 Tips On How To Improve Android App Performance
14 Tips On How To Improve Android App Performance14 Tips On How To Improve Android App Performance
14 Tips On How To Improve Android App PerformanceAndolasoft Inc
 
The Ultimate Guide to Setting Up Your WooCommerce Store
The Ultimate Guide to Setting Up Your WooCommerce StoreThe Ultimate Guide to Setting Up Your WooCommerce Store
The Ultimate Guide to Setting Up Your WooCommerce StoreAndolasoft Inc
 
Ranking The Best PHP Development Companies in the World
Ranking The Best PHP Development Companies in the WorldRanking The Best PHP Development Companies in the World
Ranking The Best PHP Development Companies in the WorldAndolasoft Inc
 
Top 8 WordPress Design and Development Trends of 2023
Top 8 WordPress Design and Development Trends of 2023Top 8 WordPress Design and Development Trends of 2023
Top 8 WordPress Design and Development Trends of 2023Andolasoft Inc
 
List of 10 Best WordPress Development Companies
List of 10 Best WordPress Development CompaniesList of 10 Best WordPress Development Companies
List of 10 Best WordPress Development CompaniesAndolasoft Inc
 
WooCommerce vs Shopify: Which is Better For Your Online Store
WooCommerce vs Shopify: Which is Better For Your Online StoreWooCommerce vs Shopify: Which is Better For Your Online Store
WooCommerce vs Shopify: Which is Better For Your Online StoreAndolasoft Inc
 
Why Choose WooCommerce For Your eCommerce Store
Why Choose WooCommerce For Your eCommerce StoreWhy Choose WooCommerce For Your eCommerce Store
Why Choose WooCommerce For Your eCommerce StoreAndolasoft Inc
 
Django Workflow and Architecture
Django Workflow and ArchitectureDjango Workflow and Architecture
Django Workflow and ArchitectureAndolasoft Inc
 
Service Oriented Architecture in NodeJS
Service Oriented Architecture in NodeJSService Oriented Architecture in NodeJS
Service Oriented Architecture in NodeJSAndolasoft Inc
 
Top Features And Updates Of Angular 13 You Must Know
Top Features And Updates Of Angular 13 You Must KnowTop Features And Updates Of Angular 13 You Must Know
Top Features And Updates Of Angular 13 You Must KnowAndolasoft Inc
 
Why Businesses Need Open Source Software
Why Businesses Need Open Source Software Why Businesses Need Open Source Software
Why Businesses Need Open Source Software Andolasoft Inc
 
What is Closure and Its Uses in PHP
 What is Closure and Its Uses in PHP What is Closure and Its Uses in PHP
What is Closure and Its Uses in PHPAndolasoft Inc
 
AngularJS vs ReactJS: Which One is Best for Next Front-end Development
 AngularJS vs ReactJS: Which One is Best for Next Front-end Development AngularJS vs ReactJS: Which One is Best for Next Front-end Development
AngularJS vs ReactJS: Which One is Best for Next Front-end DevelopmentAndolasoft Inc
 
Reactjs Vs React Native – Key Difference, Advantages, And Disadvantages
Reactjs Vs React Native – Key Difference, Advantages, And DisadvantagesReactjs Vs React Native – Key Difference, Advantages, And Disadvantages
Reactjs Vs React Native – Key Difference, Advantages, And DisadvantagesAndolasoft Inc
 
Organization Management Software Helps To Improve Your Employee Productivity
Organization Management Software Helps To Improve Your Employee ProductivityOrganization Management Software Helps To Improve Your Employee Productivity
Organization Management Software Helps To Improve Your Employee ProductivityAndolasoft Inc
 
How To Manage API Request with AXIOS on a React Native App
How To Manage API Request with AXIOS on a React Native AppHow To Manage API Request with AXIOS on a React Native App
How To Manage API Request with AXIOS on a React Native AppAndolasoft Inc
 
Institute Of Life Sciences Applicant Can Apply For Job With ILS Web Application
Institute Of Life Sciences Applicant Can Apply For Job With ILS Web ApplicationInstitute Of Life Sciences Applicant Can Apply For Job With ILS Web Application
Institute Of Life Sciences Applicant Can Apply For Job With ILS Web ApplicationAndolasoft Inc
 
What Is BuildContext In Flutter And It's Importance
What Is BuildContext In Flutter And It's ImportanceWhat Is BuildContext In Flutter And It's Importance
What Is BuildContext In Flutter And It's ImportanceAndolasoft Inc
 
How to improve your application performance
How to improve your application performanceHow to improve your application performance
How to improve your application performanceAndolasoft Inc
 
My Pill Reminder-Free Pill Reminder And Medication Tracker App
My Pill Reminder-Free Pill Reminder And Medication Tracker AppMy Pill Reminder-Free Pill Reminder And Medication Tracker App
My Pill Reminder-Free Pill Reminder And Medication Tracker AppAndolasoft Inc
 

More from Andolasoft Inc (20)

14 Tips On How To Improve Android App Performance
14 Tips On How To Improve Android App Performance14 Tips On How To Improve Android App Performance
14 Tips On How To Improve Android App Performance
 
The Ultimate Guide to Setting Up Your WooCommerce Store
The Ultimate Guide to Setting Up Your WooCommerce StoreThe Ultimate Guide to Setting Up Your WooCommerce Store
The Ultimate Guide to Setting Up Your WooCommerce Store
 
Ranking The Best PHP Development Companies in the World
Ranking The Best PHP Development Companies in the WorldRanking The Best PHP Development Companies in the World
Ranking The Best PHP Development Companies in the World
 
Top 8 WordPress Design and Development Trends of 2023
Top 8 WordPress Design and Development Trends of 2023Top 8 WordPress Design and Development Trends of 2023
Top 8 WordPress Design and Development Trends of 2023
 
List of 10 Best WordPress Development Companies
List of 10 Best WordPress Development CompaniesList of 10 Best WordPress Development Companies
List of 10 Best WordPress Development Companies
 
WooCommerce vs Shopify: Which is Better For Your Online Store
WooCommerce vs Shopify: Which is Better For Your Online StoreWooCommerce vs Shopify: Which is Better For Your Online Store
WooCommerce vs Shopify: Which is Better For Your Online Store
 
Why Choose WooCommerce For Your eCommerce Store
Why Choose WooCommerce For Your eCommerce StoreWhy Choose WooCommerce For Your eCommerce Store
Why Choose WooCommerce For Your eCommerce Store
 
Django Workflow and Architecture
Django Workflow and ArchitectureDjango Workflow and Architecture
Django Workflow and Architecture
 
Service Oriented Architecture in NodeJS
Service Oriented Architecture in NodeJSService Oriented Architecture in NodeJS
Service Oriented Architecture in NodeJS
 
Top Features And Updates Of Angular 13 You Must Know
Top Features And Updates Of Angular 13 You Must KnowTop Features And Updates Of Angular 13 You Must Know
Top Features And Updates Of Angular 13 You Must Know
 
Why Businesses Need Open Source Software
Why Businesses Need Open Source Software Why Businesses Need Open Source Software
Why Businesses Need Open Source Software
 
What is Closure and Its Uses in PHP
 What is Closure and Its Uses in PHP What is Closure and Its Uses in PHP
What is Closure and Its Uses in PHP
 
AngularJS vs ReactJS: Which One is Best for Next Front-end Development
 AngularJS vs ReactJS: Which One is Best for Next Front-end Development AngularJS vs ReactJS: Which One is Best for Next Front-end Development
AngularJS vs ReactJS: Which One is Best for Next Front-end Development
 
Reactjs Vs React Native – Key Difference, Advantages, And Disadvantages
Reactjs Vs React Native – Key Difference, Advantages, And DisadvantagesReactjs Vs React Native – Key Difference, Advantages, And Disadvantages
Reactjs Vs React Native – Key Difference, Advantages, And Disadvantages
 
Organization Management Software Helps To Improve Your Employee Productivity
Organization Management Software Helps To Improve Your Employee ProductivityOrganization Management Software Helps To Improve Your Employee Productivity
Organization Management Software Helps To Improve Your Employee Productivity
 
How To Manage API Request with AXIOS on a React Native App
How To Manage API Request with AXIOS on a React Native AppHow To Manage API Request with AXIOS on a React Native App
How To Manage API Request with AXIOS on a React Native App
 
Institute Of Life Sciences Applicant Can Apply For Job With ILS Web Application
Institute Of Life Sciences Applicant Can Apply For Job With ILS Web ApplicationInstitute Of Life Sciences Applicant Can Apply For Job With ILS Web Application
Institute Of Life Sciences Applicant Can Apply For Job With ILS Web Application
 
What Is BuildContext In Flutter And It's Importance
What Is BuildContext In Flutter And It's ImportanceWhat Is BuildContext In Flutter And It's Importance
What Is BuildContext In Flutter And It's Importance
 
How to improve your application performance
How to improve your application performanceHow to improve your application performance
How to improve your application performance
 
My Pill Reminder-Free Pill Reminder And Medication Tracker App
My Pill Reminder-Free Pill Reminder And Medication Tracker AppMy Pill Reminder-Free Pill Reminder And Medication Tracker App
My Pill Reminder-Free Pill Reminder And Medication Tracker App
 

How To Organize And Structure Your SASS Code

  • 1. From the Resource Library of Andolasoft.Inc | Web and Mobile App Development Company 1
  • 2. From the Resource Library of Andolasoft.Inc | Web and Mobile App Development Company 2 How To Organize And Structure Your SASS Code SASS (Syntactically awesome style sheets) is an extension of the CSS which adds syntactic power to the basic CSS language making it easier for developers to write CSS. It is just a CSS preprocessor, so that you can write CSS in an easy and convenient way. “Sass is a meta-language on top of CSS that's used to describe the style of a document cleanly and structurally, with more power than flat CSS allows. Sass both provides a simpler, more elegant syntax for CSS and implements various features that are useful for creating manageable style sheets.” “Sass is an extension of CSS3, adding nested rules, Variables, mixins, selector inheritance, and more. It’s translated to well-formatted, standard CSS using the command line tool or a web- framework plugin.” It’s Sass not SASS. Sass doesn’t stand for anything, except maybe making your CSS Sassier. Sass makes CSS more Sassy because it’s a preprocessor. Preprocessors make writing code easier. If it helps you 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 cleverer. TheHistory of SASS: ▪ Sass was first given life by Hampton Catlin in 2006, later supported by Natalie weizembaum and ChrisEpstein ▪ Sass started life in ruby community ▪ Sass supports two syntaxes –Indentation syntax with file ext .sass –CSS compatible syntax with file ext .scss ▪ Sass is free to use, require no license. Why Use SASS? ▪ Modularize (@import) ▪ Variables for maintainability ▪ Mixins improves reusability ▪ Reduces redundant rules (keep it DRY)
  • 3. From the Resource Library of Andolasoft.Inc | Web and Mobile App Development Company 3 ▪ Scalable and Maintainable ▪ Sass is completely compatible with all versions of CSS ▪ Sass reduces repetition of CSS and therefore saves time ▪ It provides the document style in a good, structured format, better than vanilla CSS ▪ It uses re-usable methods, logic statements and some of the built-in functions such as color manipulation, mathematics and parameter lists SASS and SCSS Two available syntaxes SASS ▪ HAML-style indentation ▪ No brackets or semi-colons, based on indentation ▪ Less characters to type ▪ Enforced conventions/neatness SCSS ▪ Semi-colon and bracket syntax ▪ Superset of normal CSS ▪ Normal CSS is also valid SCSS ▪ Newer and recommended How toInstall SASS on Computer Install Live SASS Compiler Extension in VS Code ▪ Select the Extensions tab from the sidebar. Click on the Extensions tab from the sidebar ▪ Search for Live Server in the search box ▪ Search for “Live Sass Compiler” from the search box ▪ Click on the Install button ▪ It is now in NodeJS package also ▪ First install NodeJS
  • 4. From the Resource Library of Andolasoft.Inc | Web and Mobile App Development Company 4 ▪ then Enter NPM install –g sass The SASS File structure pattern sass/ | |– abstracts/ (or utilities/) | |– _variables.scss // Sass Variables | |– _functions.scss // Sass Functions | |– _mixins.scss // Sass Mixins | |– base/ | |– _reset.scss // Reset/normalize | |– _typography.scss // Typography rules | |– components/ (or modules/) | |– _buttons.scss // Buttons | |– _carousel.scss // Carousel | |– _slider.scss // Slider | |– layout/ | |– _navigation.scss // Navigation | |– _grid.scss // Grid system | |– _header.scss // Header | |– _footer.scss // Footer | |– _sidebar.scss // Sidebar | |– _forms.scss // Forms | |– pages/ | |– _home.scss // Home specific styles | |– _about.scss // About specific styles | |– _contact.scss // Contact specific styles | |– themes/ | |– _theme.scss // Default theme | |– _admin.scss // Admin theme | |– vendors/ | |– _bootstrap.scss // Bootstrap | |– _jquery-ui.scss // jQuery UI | `– main.scss // Main Sass file
  • 5. From the Resource Library of Andolasoft.Inc | Web and Mobile App Development Company 5 @import 'abstracts/variables'; @import 'abstracts/functions'; @import 'abstracts/mixins'; @import 'vendors/bootstrap'; @import 'vendors/jquery-ui'; @import 'base/reset'; @import 'base/typography'; @import 'layout/navigation'; @import 'layout/grid'; @import 'layout/header'; @import 'layout/footer'; @import 'layout/sidebar'; @import 'layout/forms'; @import 'components/buttons'; @import 'components/carousel'; @import 'components/slider'; @import 'pages/home'; @import 'pages/about'; @import 'pages/contact'; @import 'themes/theme'; @import 'themes/admin'; ▪ Our folders would typically contain the following like abstracts contains tools, helpers, variables, mixins etc. ▪ Base contains boilerplate code for the project. This includes styles such as resets, typography etc. ▪ Components contains all the smaller page components like separated into multiple smaller files like slider, carousel etc. ▪ Layout contains the layout styles, separated into several smaller files like header, footer etc. ▪ Pages contains page-specific styles. For example, the home page and search results page typically looks very different. ▪ Themes contains files that are theme specific, like alternate color schemes (if any).
  • 6. From the Resource Library of Andolasoft.Inc | Web and Mobile App Development Company 6 ▪ Vendors contains third party code from external frameworks and libraries like jQueryUi, Bootstrap etc. ▪ Our main file is only used to import all the other files. Reasons We Love SASS Variables ▪ Sass allows to declare variables that can be used throughout the style sheet ▪ Variables begin with $ and are declared like properties They can have any value that’s allowed for a CSS property, such as colors, numbers, or text Variables: SASS vs. SCSS
  • 7. From the Resource Library of Andolasoft.Inc | Web and Mobile App Development Company 7 Mixins Mixins allow to re-use whole chunks of CSS, properties or selectors Mixins are defined using the “@mixin” directive, which takes a block of styles that can then be included in another selector using the “@include” directive Mixins: SASS vs. SCSS
  • 8. From the Resource Library of Andolasoft.Inc | Web and Mobile App Development Company 8 Nesting ▪ Often in CSS there are several selectors that begin in the same way ▪ Sass avoids repetition by nesting selectors within one another Properties can be nested too ▪ Pseudo classes can be nested too (e.g. :hover) ▪ Sass special character &in a selector & is replaced with the parent selector
  • 9. From the Resource Library of Andolasoft.Inc | Web and Mobile App Development Company 9 Nesting: SASS vs. SCSS
  • 10. From the Resource Library of Andolasoft.Inc | Web and Mobile App Development Company 10 Imports Style sheets can be big: the @import directive that allows to break styles up into multiple style sheets Operator and functions ▪ Sass supports basic math operations and many useful functions ▪ http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html ▪ The standard math • Operations(+, -, *, /, and %) are supported for numbers There are many useful functions for colors, e.g. To change lightness, hue, saturation,
  • 11. From the Resource Library of Andolasoft.Inc | Web and Mobile App Development Company 11 Selector inheritance Sass can tell one selector to inherit all the styles of another without duplicating the CSS properties Conclusion: Organizing code is essential for developers and together with all other skills.It is the most effective way to improve the functioning of the site. And even though there are multiple ways of organization and different strategies, opting for simplicity helps you avoid the dangerous pitfalls. And finally, there is no right or wrong choice since everything depends on the developer’s work strategies.