Is there any way to create dynamic utility classes in css?

Is there any way to do something like... <h1 class="pad-5">Some Heading</h1> to apply a padding of 5px to the h1 tag. And this should be dynamic. For example, If I write class="pad-15", it should give padding of 15px.

And I want to do this by creating one single ruleset. Not by defining different classes of pad-5, pad-15 and so on individually.

In css file, it should be something like...

.pad-[$value]{
     padding: $value;
}

So, is there any way of doing this?



Read more here: https://stackoverflow.com/questions/65713473/is-there-any-way-to-create-dynamic-utility-classes-in-css

Content Attribution

This content was originally published by Prashant Kumar at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: