Working with SCSS

Working with SCSS

Canvas ships its full SASS source so you can change colors, spacing, typography, and component styles at the source and recompile a single style.css. Editing variables is the recommended way to rebrand the template without overriding compiled CSS.

Structure

The SASS lives in the sass/ folder and is assembled by the root style.scss. style.scss imports the partials in order: variables and mixins first, then Bootstrap, core CSS, content blocks, shortcodes, forms, and plugins.

style.scss              # master file that @imports everything
sass/
  _variables.scss       # colors, fonts, sizes: edit this first
  _mixins.scss
  bootstrap/            # bundled Bootstrap source
  _root.scss
  _layouts.scss
  _typography.scss
  _utilities.scss
  _header.scss
  _sliders.scss
  _content.scss
  _forms.scss
  _footer.scss
  _shortcodes.scss      # @imports the shortcodes/ partials
  shortcodes/
    _buttons.scss
    _pricing.scss
    _carousel.scss
    ... (one partial per shortcode)

The top of style.scss shows the import chain:

// Initialize
@import "sass/variables";
@import "sass/mixins";

// Bootstrap
@import "sass/bootstrap/bootstrap";

// Core CSS
@import "sass/root";
@import "sass/layouts";
@import "sass/typography";
@import "sass/utilities";

// Content Blocks
@import "sass/header";
@import "sass/sliders";

// Shortcodes
@import "sass/shortcodes";

// Forms
@import "sass/forms";

Setup

Edit variables in sass/_variables.scss, then recompile with the bundled Gulp tasks defined in gulpfile.js.

// sass/_variables.scss
$slider-caption-width       : 550px;
$slider-caption-font-size   : 1.375rem;
$slider-caption-font-weight : 300;

Install dependencies once, then run the SCSS compile task. The scsscompile task compiles style.scss to style.css (and generates the RTL stylesheet):

npm install
npx gulp scsscompile

The compile pipeline reads ./style.scss, runs SASS, concatenates to ./style.css, and applies autoprefixer:

function compileSCSS() {
  return gulp.src('./style.scss', { sourcemaps: true })
    .pipe(plumber())
    .pipe(sass({ silenceDeprecations: silencedSassDeprecations }).on('error', sass.logError))
    .pipe(concat('./style.css'))
    .pipe(postcss([ autoprefixer() ]))
    .pipe(gulp.dest('./', { sourcemaps: '.' }));
}

exports.scsscompile = series(compileSCSS, convertRTL);

Available Gulp tasks

Defined at the bottom of gulpfile.js:

  • gulp scsscompile: compile style.scss to style.css and produce the RTL stylesheet.
  • gulp rtl: convert the compiled CSS to RTL only.
  • gulp cssminify: minify the compiled CSS.
  • gulp jsminify / gulp minify: minify JS, or CSS and JS together.
  • gulp buildjs: concatenate and build the bundled JS (plugins and functions).
  • gulp watch: watch source files and rebuild on change.

Tips

  • Change variables in sass/_variables.scss rather than editing style.css directly, so your customizations survive a recompile.
  • To restyle a single shortcode, edit its partial under sass/shortcodes/ (for example _pricing.scss), then run gulp scsscompile.
  • Use gulp watch while developing so style.css rebuilds automatically as you save SCSS files.

How to Use

  1. 1

    Step 1 - Head Section

    Add the SASS related CSS in the Document .

    <head>
    
    	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
    	<meta name="author" content="SemiColonWeb" />
    
    	<!-- Stylesheets
    	============================================= -->
    	<link rel="stylesheet" href="style.css" type="text/css" />
    	<link rel="stylesheet" href="css/font-icons.css" type="text/css" />
    	<link rel="stylesheet" href="css/animate.css" type="text/css" />
    	<link rel="stylesheet" href="css/magnific-popup.css" type="text/css" />
    
    	<link rel="stylesheet" href="css/custom.css" type="text/css" />
    	<meta name="viewport" content="width=device-width, initial-scale=1" />
    
    	<!-- Document Title
    	============================================= -->
    	<title>Page | Canvas</title>
    
    </head>

    Note: No need to add Bootstrap, dark or RTL related CSS files separately.

  2. 2

    Step 2 - Unwanted Files

    You can remove the files you don't need for your Project from the style.scss.

  3. 3

    Step 3 - Editing

    Canvas Core Editable files:

    • HTML/sass/_variables.scss: You will find the complete list of variables specific to Canvas in HTML/scss/_variables.scss.

    • HTML/sass/_bootstrap/: Full Package of Bootstrap SCSS files.
      Note: We don't recommend overwriting the original file. Bootstrap SASS

    • HTML/sass/shortcodes/: Canvas's Shortcodes related files

    • HTML/sass/_dark.scss: Canvas's Dark file.

    • HTML/sass/_rtl.scss: Canvas's RTL file. By default it's not enabled in the _variables.scss file $RTL-template: false !default;. Simply set it to true to enable RTL. (don't forget to customize HTML Structure according to standard RTL requirements. No need to add any links in section)

Was this page helpful?