Can I use variables for selectors?

Johansrk picture Johansrk · Oct 5, 2012 · Viewed 27.3k times · Source

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

glortho picture glortho · Oct 8, 2012
$gutter: 10;

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

If used in a string for example in a url:

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