Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

concatenate strings using sass

Tags:

css

sass

grid

I would like to write a sass loop like so.

fractions: '';
@for $i from 1 through 4 {
    $fractions : $fractions + 1fr + '';
    .grid-#{$i} {
        grid-template-columns: fractions;
        display: block;
    }
}

I would like the output to be something like,

.grid-1 {
    grid-template-columns: 1fr; 
}
.grid-4 {
    grid-template-columns: 1fr 1fr 1fr 1fr; 
}

not

.grid-1 {
    grid-template-columns: " 1fr"; 
}
.grid-4 {
    grid-template-columns: " 1fr 1fr 1fr 1fr"; 
}

I'm looking for a sass utility/function that I can use to remove the quote around the strings.

like image 367
One Avatar asked Jul 09 '18 11:07

One


People also ask

Which string function is used to give quotes to the string in Saas?

1. quote($string) Function: This function adds the quotes to the unquoted string and returns the quoted string.

What is interpolation in Sass?

Interpolation allows us to interpolate sass expressions into a simple SASS or CSS code. Means, you can define ( some part or the whole ) selector name, property name, CSS at-rules, quoted or unquoted strings etc, as a variable. Interpolation is a new principle and it is widely used in SASS.

What is SassScript?

SassScript is a script which allows us to compute CSS selector, property or value using Sass expression. We'll look at expressions in this chapter and explore data types, SassScript control directives, operations and functions in the next few chapters. All of these can be use in SassScript.


1 Answers

$fractions:'';
@for $i from 1 through 4 {
    $fractions : $fractions + 1fr + ' ';
    .grid-#{$i} {
        grid-template-columns: #{$fractions};
        display: block;
    }
}
like image 178
ReSedano Avatar answered Oct 30 '22 09:10

ReSedano