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.


amazon

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS? #Aug 1 What is Zdog? #Aug 1 How to add before after image effect using pure CSS? #Jul 31 Add animation to your skills bar using CSS #Jul 31 Use SwiperJS to create mobile touch sliders fast
You might also like these
CREATE TABLE Examples in PostgreSQLPostgresHow to change the Login Logo in WordPress?WordPressWhat’s a Web Storage API in JavaScript?JavaScriptGap in Flex?CSSRelative Length Units in CSSCSSWhat is Hoisting in JavaScript?JavaScriptHow to create a Progress Bar using JavaScript?JavaScriptHow to convert an object from API to JSON array in Angular 9?AngularNew to  Drupal? Here’s What You Need to KnowDrupalWhat is the difference between float and double?MiscellaneousCanvas Drawing in HTML5HTMLHow to make a UILabel clickable in Swift 5?Swift