Yogesh Chauhan's Blog

Configuring Modules with @forward rule in SCSS (Sass)

in SCSS on June 3, 2021

Configuring modules with @forward rule is similar to configuring modules with @use rule.

The difference is that you can use the !default flag in it’s configuration while configuring with @forward module.

That is very handy since you can use the other modules members with no values can have default values and if they have values then you can use that value.

For e.g. let’s say you have a _fonts.scss file with the following styles:


// _fonts.scss
$black: #000 !default;

.arial {
  color: $black;
}

Let’s forward that stylesheet into another one.


// _fonts_adjusted.scss
@forward 'fonts' with (
  $black: #222 !default,
);

Finally, let’s use it in the main stylesheet.


// main.scss
@use 'fonts_adjusted' with ($black: #333);

This is how it’ll compile into CSS at the end:


// main.scss
.arial {
  color: #333;
}


Most Read

#1 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to uninstall Cocoapods from the Mac OS?

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
Social Media Colors: LESS VariablesMiscellaneous4 different ways to create JavaScript ObjectsJavaScriptWhat’s new in WordPress 5.5?WordPressHow to import a CSS file using PHP code and not HTML code?PHPHow to Display Related Posts in WordPress?WordPressHow to select an element using its ID without the high specificity of the ID selector?CSSCreate a menu with a curtain falling animation using CSS and JavaScriptCSSSQL Left JoinSQL/MySQLHow does Next.js load pages faster?NextJSCheck If a String Contains a Specific Word in PHPPHPIs there a CSS parent selector?CSSKubernetes vs. Docker? It’s a misleading phraseMiscellaneous