Sass @each Rules

You are Here:

Sass @each Rules

Sass @each rules is used to loop through elements in a list or each pair in a map.

Sass @each rules is mostly used for repetitive styles that only have a few variations between them.

Sass @each Rules using 'List'

In the following example, we will loop through a list.

Example

SASS TO CSS CONVERTER
$sizes: 40px, 60px, 80px; @each $size in $sizes { .icon-#{$size} { font-size: $size; height: $size; width: $size; } }

Syntax

@each variable in expression { // code };

Sass @each Rules using 'Map'

In the following example, we will loop through a map.

Example

SASS TO CSS CONVERTER
$entities: ("one": "\000A7", "two": "\02100", "three": "\02105"); @each $name, $entity in $entities { .icon-#{$name}:before { display: inline-block; font-family: "Icon Font"; content: $entity; } }

Reminder

Hi Developers, we almost covered 99.1% of Sass Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in Sass.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author