


How to Generate a Comma-Separated List of CSS Classes Dynamically in SCSS?
Generating a Comma-Separated List of Classes Dynamically in SCSS
Creating dynamic grid systems in SCSS often requires generating a list of column classes separated by commas. This simplifies the application of common styles across varying column counts. However, writing such code can be challenging.
Dynamic Column Creation
The provided SCSS code successfully creates column classes based on a variable $columns. However, generating a comma-separated list of these classes remains a hurdle.
Using @extend
Instead of creating individual class definitions for each column, consider using the @extend directive. By defining a mixin that extends pre-defined float styles, you can achieve the desired effect:
%float-styles { float: left; } @mixin col-x-list { @for $i from 1 through $columns { .col-#{$i}-m { @extend %float-styles; } } }
In this code:
- The %float-styles placeholder defines the styling to be extended.
- The @mixin col-x-list creates the list of classes.
- The @for loop iterates through column numbers.
- Each class extends the %float-styles, inheriting its float property.
Resulting CSS
The CSS generated using this approach will resemble the following:
.col-1-m, .col-2-m, .col-3-m, .col-4-m, .col-5-m, .col-6-m, .col-7-m, .col-8-m, .col-9-m, .col-10-m, .col-11-m, .col-12-m { float: left; }
This provides a comma-separated list of classes that inherit the float property from the %float-styles placeholder. By leveraging @extend, you can simplify the code while maintaining the desired functionality.
The above is the detailed content of How to Generate a Comma-Separated List of CSS Classes Dynamically in SCSS?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Let’s attempt to coin a term here: "Static Form Provider." You bring your HTML

At the start of a new project, Sass compilation happens in the blink of an eye. This feels great, especially when it’s paired with Browsersync, which reloads

In this week's roundup of platform news, Chrome introduces a new attribute for loading, accessibility specifications for web developers, and the BBC moves

This is me looking at the HTML element for the first time. I've been aware of it for a while, but haven't taken it for a spin yet. It has some pretty cool and

Buy or build is a classic debate in technology. Building things yourself might feel less expensive because there is no line item on your credit card bill, but

For a while, iTunes was the big dog in podcasting, so if you linked "Subscribe to Podcast" to like:

In this week's roundup, a handy bookmarklet for inspecting typography, using await to tinker with how JavaScript modules import one another, plus Facebook's

The document head might not be the most glamorous part of a website, but what goes into it is arguably just as important to the success of your website as its
