This will instruct about Sass syntax and project setting up information.
It supports two types of syntaxes.
SCSS (Sassy CSS):
- This follows CSS-like syntax with extensions.
- This is easier and readable. Example:
$primary-color: blue;
.button {
background-color: $primary-color;
padding: 10px 15px;
}Sass (Indented Syntax):
- This uses indentation to define blocks.
- This is more concise and minimalistic. Example:
$primary-color: blue;
.button
background-color: $primary-color
padding: 10px 15pxA typical Sass project will follow similar structure, which might look like below:
project/
styles/
_variables.scss
_mixins.scss
_base.scss
main.scss
For large-scale projects:
project/styles/
layout/
_layout.scss
_header.scss
_footer.scss
_sidebar.scss
components/
_button.scss
_form.scss
_card.scss
_modal.scss
_table.scss
utilities/
_utilities.scss
_base.scss
_typography.scss
_colors.scss
_mixins.scss
_functions.scss
main.scss
-
layoutdirectory is place for different chunks of styles for different sections._layout.scsscontains overall layout styles such as grid system, containers and spacing._header.scsscontains styles implementation for header section_footer.scsscontains styles implementation for footer section_sidebar.scsscontains styles implementation for sidebar section
-
componentsdirectory is place for different chunks of styles for different components._button.scsscontains styles for the button components might reused through out the project._form.scsscontains styles for the form components might reused through out the project._card.scsscontains styles for the card components might reused through out the project._modal.scsscontains styles for the modal components might reused through out the project._table.scsscontains styles for the table components might reused through out the project.
-
utilitiesdirectory is place for different chunks of styles for different utilities._utilities.scsscontains classes for common styles like margin, padding, text alignment.
-
project/stylesdirectory is place for base styles and their resources._variables.scsscontains global variables to be used through out the project._base.scsscontains global styles like resets, typography and color palettes._typography.scsscontains styles including font size, line height, font families._colors.scssdefines theme and color palettes._mixins.scsscontains reusable mixins for common styles like border-radius, box-shadow, transitions._functions.scssdefines custom functions.main.scssis the root and main style file for overall project which organize all other styles and resources.
Sass supports two types of comments:
Single-line comments:
// This is a single-line commentMulti-line comments:
/*
This is a
multi-line comment
*/Sass stylesheets loads other Sass files by URL of the file path. This means instructed to use forward slashes / rather than backslashes \ on any operating systems.
URLs are case-sensitive. As the same, Sass will consider Base.scss and base.scss to be different eventhough on a case-insensitive filesystem. Make sure the Sass file names and URLs match the actual names and URLs on disk, or this will might load twice or won’t work.
Sass can load other stylesheet as relative to the current file first. If it not exist then it proceed with defined load path. Make sure the file name conflict with other Sass stylesheet.
Relative imports can be supported and does not require to use ./ relative import URL.
Sass has a feature of Partials. It means to load other stylesheet as modules and not to be compiled.
Sass can find _index.scss or _index.sass in a directory and it will be loaded automatically when mention the URL for the directory itself rather than mentioning custom entry point for styles.