I'm writing a stylesheet for a web site where I need to support multiple skins/themes. For example, one theme might be black-on-white with red as the primary color, and another theme might be white-on-black with maroon as the primary color.
Almost all of the CSS from one theme translates over to the other theme, except for things like foreground and background color.
As an illustrative example, say we have a div. The size and position of that div is fixed between themes, but the color might change. We could separate this into three different CSS files like so:
/* main.css */
#box {
position: absolute;
top: 50px;
left: 50px;
width: 200px;
height: 200px;
}
/* theme1.css */
#box {
backround-color: red;
}
/* theme2.css */
#box {
background-color: maroon
}
Then the end user would load main.css plus one of the theme stylesheets. Another design would be to put a class on the body element, and use selectors to apply the right colors, all in one CSS file. For example,
#box {
position: absolute;
top: 50px;
left: 50px;
width: 200px;
height: 200px;
}
body.theme1 #box {
backround-color: red;
}
body.theme2 #box {
background-color: maroon
}
The advantage of the second option is that there are fewer HTTP requests. The advantage of the first option is that the user needs to load less data from the server. This is especially important when there are many different themes, and (as in my use case) when inlined background images significantly increase the weight of the CSS files.
So my question is, how can I leverage the power of CSS pre-processors like SASS or Stylus to create multiple CSS theme files?
I envision something like this maybe:
@theme(theme1) {
$primaryColor: red;
}
@theme(theme2) {
$primaryColor: maroon;
}
#box {
position: absolute;
top: 50px;
left: 50px;
width: 200px;
height: 200px;
background-color: $primaryColor;
}
which would in turn generate the three CSS files listed above in the first example.
Any ideas? Does something like this already exist?