I have multiple themes on my website and users can just switch between multiple themes by clicking on a javascript link. I have 5 CSS files to handle the layout of all of the themes. 1 is for structure, 3 are for colors etc for different themes, and 1 mon for some other stuff.
my css filenames read like this ..
main.css, red.css, green.css, black.css, others.css
With red, green and black css files are defined as alternate stylesheet
s.
I have installed YSLOW! and get "This page has 5 external stylesheets. Try bining them into one."
I was just wondering if it is possible to bine most of them into a fewer numbers of CSS files. I know that we can define `
@media screen
{
//screen
}
@media print
{
//print
}
` sections in a single CSS file. Can something like this be done for multiple CSS files as well?
Thanks for your help.
I have multiple themes on my website and users can just switch between multiple themes by clicking on a javascript link. I have 5 CSS files to handle the layout of all of the themes. 1 is for structure, 3 are for colors etc for different themes, and 1 mon for some other stuff.
my css filenames read like this ..
main.css, red.css, green.css, black.css, others.css
With red, green and black css files are defined as alternate stylesheet
s.
I have installed YSLOW! and get "This page has 5 external stylesheets. Try bining them into one."
I was just wondering if it is possible to bine most of them into a fewer numbers of CSS files. I know that we can define `
@media screen
{
//screen
}
@media print
{
//print
}
` sections in a single CSS file. Can something like this be done for multiple CSS files as well?
Thanks for your help.
Share Improve this question edited Jul 7, 2009 at 9:58 TigerTiger asked Jul 7, 2009 at 9:42 TigerTigerTigerTiger 10.8k16 gold badges58 silver badges72 bronze badges4 Answers
Reset to default 6Your main and other can be bined, then rather than attaching the other three, can you not jsut load them with javascript when necessary?
Something like this:
<link rel="stylesheet" href="style1.css" id="stylesheet">
<script type="text/javascript">
function changeStyle() {
document.getElementById('stylesheet').href = 'style2.css';
}
</script>
Combine the two mon stylesheets, and ignore YSlow for the alternative ones. YSlow is a tool, not the enforcer of the law.
You could, instead of swapping stylesheets, bine the stylesheets into one and change the colours with a class on the body instead. This is easier to describe with an example:
Say you currently have
red.css
body { color:red; }
green.css
body { color:green; }
and you swap between them with JavaScript.
Why not change that to:
colors.css
body.red { color:red; }
body.green { color:green; }
and swap the class on the body with JavaScript. Then you only have one CSS file and the JavaScript is much simpler too.
You could add a class attribute to the body tag and change this by JavaScript
. Then you could bine all stylesheet into one.
An interessting tool for writing stylesheets is HSS it helps you to create nested structures.