什么是好的CSS策略? [英] What is a good CSS strategy?

查看:142
本文介绍了什么是好的CSS策略?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个大的ASP.Net网站,有一个单一的css样式表,失去控制。

We have a large ASP.Net website that has a single css stylesheet which is getting out of control.

我想使用以下策略从 http://www.techrepublic.com/article/developing- a-css-strategy / 5437796 / ),这似乎对我是合乎逻辑的...

I am thinking of using the the following strategy (taken from http://www.techrepublic.com/article/developing-a-css-strategy/5437796/) which seems logical to me...

你可能有一个CSS文件专门用于单独的CSS文件用于可识别的网站页面子集(例如特定部门的页面或具有不同布局样式的页面)。对于特定页面唯一的样式,请为每个页面使用单独的CSS文件(如果有太多样式可以轻松地放在文档标题中)。您可以为每个网页链接或导入适当的CSS文件,以便加载显示该网页所需的所有样式,但只显示在其他网页上的非必要样式很少。

you might have one CSS file devoted to sitewide styles and separate CSS files for identifiable subsets of site pages (such as pages for a specific department or pages with a different layout style). For styles that are unique to a specific page, use a separate CSS file for each page (if there are too many styles to fit comfortably in the document header). You link or import the appropriate CSS files for each page, so that you load all the styles needed to display that page, but very few unnecessary styles that only appear on other pages.

这是一个很好的方法吗?

Is this a good way to proceed? What are the alternatives?

推荐答案

我认为最好的选择是划分css:

I think the best option is to divide css in:

-layout.css

-layout.css

-content.css

-content.css

具体你可以添加更多类似css的广告:ads.css或一个css的特定部分。

Then if you need other more specific you can add more like an css for the ads: ads.css, or one css for a specific section.

我也将添加ie.css IE css hacks 。

I would also add ie.css for IE css hacks.

我不会说只为一个页面创建一个CSS:如果你使用太多的CSS,你可以有的问题是你的页面将不得不做更多请求到服务器,这将减慢您的页面。
这就是为什么我建议你实现一个HttpHandler,它将创建一个缓存副本只有一个文件的css你需要的时刻。查看这里:
http://blog.madskristensen .dk / post / Combine-multiple-stylesheets-at-runtime.aspx

I would not speak about creating one css for only one page: the problem you can have if you use too many css, is that your page will have to do more requests to the server and this will slow your page. This is why i recommend you to implement an HttpHandler which will create a cache copy in only one file of the css you need at the moment. Look here: http://blog.madskristensen.dk/post/Combine-multiple-stylesheets-at-runtime.aspx

这篇关于什么是好的CSS策略?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆