admin管理员组文章数量:1244384
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.
本文标签:
版权声明:本文标题:javascript - How to avoid this? Yslow -> "This page has 5 external stylesheets. Try combining them into one.& 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740201711a2240336.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论