Is it possible to create something like this with SASS?
$prefix: *
*-var1: 150px
*-var2: 150px
*-var3: 350px
This could be very useful for organising a stylesheet
Is it possible to create something like this with SASS?
$prefix: *
*-var1: 150px
*-var2: 150px
*-var3: 350px
This could be very useful for organising a stylesheet
Absolutely...
SASS:
$variableName: "myStyle";
#{$variableName}_r1{ border: 1px solid red; }
Produces CSS:
myStyle_r1 {
border: 1px solid red;
}
The key is the interpolation - #{$variableName} - which basically dumps the variableName out as it was written...
In Sass 3.3 there are a couple of new features that will likely solve your need for doing this, and greatly help with organizing stylesheets
You now have maps, which allow you to essentially create objects containing variables.
You can do the following:
$colors: (
header: #b06,
text: #334,
footer: #666777,
)
.header {
background-color: map-get($colors, header)
}
As well as the new ability to prefix css selectors like so:
// Sass:
.button {
&-primary { background: orange; }
&-secondary { background: blue; }
}
// Output:
.button-primary { background: orange; }
.button-secondary { background: blue; }
Further reading: http://thesassway.com/news/sass-3-3-released