CSS @import Best Practices

不想你离开。 提交于 2019-11-30 19:32:45

From pure experience:

While working you can keep everything separated (reset.css, forms.css, main.css, etc.) if you find it hard to work with one single file - I don't do even that..

When putting on production - keep everything in one file - no imports - 1 server request - minimize your css.

Exception is an additional ie.css if you want to keep your main.css hack free/pass validation (I also don't do this since not a single of my clients cared about validation - people want it to work, badges are not a trend :) - so i just use hacks trough my main.css (#, _, etc.))

It's best to avoid @import.

According to Steve Souders, combining, @import and link or embedding @import in other stylesheets will cause sequential rather than parallel downloads.

There are other problems as well.

http://www.stevesouders.com/blog/2009/04/09/dont-use-import/

Yahoo also recommends against @import, noting that

In IE @import behaves the same as using at the bottom of the page, so it's best not to use it.

http://developer.yahoo.com/performance/rules.html#csslink

I usually use one stylesheet and use link to grab it.

For exceptionally large sites, I use one main stylesheet and then smaller sheets for sections that need additional styling, adding those stylesheets to various pages as necessary.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!