Johansrk Johansrk - 6 months ago 10
CSS Question

Can I use variables for selectors?

I have this variable:

$gutter: 10;


I want to use it in a selector like so SCSS:

.grid+$gutter {
background: red;
}


so the output becomes CSS:

.grid10 {
background: red;
}


But this doesn't work. Is it possible?

Answer
$gutter: 10;

.grid#{$gutter} {
    background: red;
}

If used in a string for example in a url:

background: url('/ui/all/fonts/#{$filename}.woff')
Comments