Yogesh Chauhan's Blog

Content Blocks in SCSS (Sass)

in SCSS on April 25, 2021

As we saw in the animation example, we can pass the whole block of style in the @mixin rules.

The block of style called a “content block” in SassScript.

How to pass the content block?

Just include @content at-rule in @mixin body to pass the entire content block.

Just like this:


@mixin hover {
  &:not([disabled]):hover {
    @content;
  }
}

Examples: pass the content block

Checkout the working example:


@include multiple @content

A Content Block can only see (has access to) the local variables, only where the @mixin is included. In other words, a Content Block is lexically scoped.

How to pass arguments to Content Blocks?

Passing arguments in content blocks is same as passing arguments to any function.

Just add arguments to @content() when you include it in @mixin.

How to accept the arguments?

Just write the @include using ().


Examples: pass arguments to Content Blocks

Here’s the example above with passing arguments and taking it to apply style.

If you pass arguments to content blocks using mixin then the content blocks must accept the arguments.


Most Read

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

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
How to include CSS and JavaScript files in your WordPress plugin?WordPressWhat’s a repository on Github?MiscellaneousDebugging in WordPress Part 1: WP_DEBUGWordPressVariables and Distance Functions in SCSS (Sass)SCSSCanvas Drawing in HTML5HTMLWill SQL (Relational) Database become obsolete?SQL/MySQLHow to get the first element with a class name xyz using JavaScript?JavaScriptWhat is an API?Miscellaneousapply_filters function in WordPressWordPressHow to set opacity or transparency using CSS?CSSPHP arrays for US states’ full names and abbreviationsPHPHow to create Glowing Texts using CSS?CSS