concatenate strings using sass

2019-07-07 16:51发布

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.

标签: css sass grid
1条回答
Viruses.
2楼-- · 2019-07-07 17:17
$fractions:'';
@for $i from 1 through 4 {
    $fractions : $fractions + 1fr + ' ';
    .grid-#{$i} {
        grid-template-columns: #{$fractions};
        display: block;
    }
}
查看更多
登录 后发表回答