@import url()做一下总结:
1:@import url()机制是不同于link的,link是在加载页面前把css加载完毕,而@import url()则是读取完文件后在加载,所以会出现一开始没有css样式,闪烁一下出现样式后的页面(网速慢的情况下)。
2:@import 是css2里面的,所以古老的ie5不支持。
3:当使用javascript控制dom去改变样式的时候,只能使用link标签,因为@import不是dom可以控制的。
4:link除了能加载css外还能定义RSS,定义rel连接属性,@import只能加载css
@import url(xxx.css); 有最大次数的限制,经测试IE6的最大次数是31次,第32个import及
虽然最多只能import 31次,但不会影响css里面的其他规则,如body{}的定义还能正常显示。
Firefox 没有发现有import的最大值。
引用
31 stylesheets per file
If you are an ASP.NET developer and you develop mid-sized projects using App_Themes the chances are that you will hit this limit sooner than later. The problem is that App_Themes engine iterates through the skin folder and loads every CSS file kept in there regardless if it is needed or not. Every Internet Explorer version (including IE8 and unfortunately the IE9 preview released recently) on the other hand has the limit of loading only 31! stylesheets per file and thus fails to load all CSS files in a theme if they are more than 31. Another thing is that style tags in the HTML head or body are also counted as stylesheets (they are in fact parsed and created as different stylesheet objects) and are contributing to the problem - the more style tags you have, the less stylesheets you can include.
Unfortunately this bug is transferred to our RadControls as well. If you use a big number of RadControls and custom skins for them in a theme and just dump all the CSS files in it, you are in trouble.
Click here for a demo of a broken project which fails to load its CSS in all IE browsers. You can find the original project zipped at the end of this blog post.
There are several ways to fix the issue. One of them is to add a RadStyleSheetManager to your page - it has a stylesheet combining feature which is switched on by default and that will help you to partially reduce the number of loaded CSS files. However this method fixes the issue only to an extent (combines only the non-external skins) and may lead you to the second CSS limit in Internet Explorer which we will discuss soon enough.
Fortunately there is an alternative solution - it involves removing all the stylesheets from the App_Themes folder, moving them somewhere else within the site and creating there one or several CSS files in which you link the removed CSS files one by one using @import declarations.
Click here for a demo of a fixed site using the latter method. A zip with the original is awaiting you at the end of the article.
4095 selectors in a CSS file
A little less known limitation in all Internet Explorer browsers is the maximum number of possible selectors in a CSS file - 4095. This means that if you stumble upon the 31 stylesheets bug and decide to combine all your stylesheets to avoid it - at the end you will probably be in similar situation as in the beginning.
Unfortunately the only fix for this is splitting the file to several different CSS files and using the described above @import method to include them in your project.
Click here to see a test case of this bug or download the source below.
http://stackoverflow.com/questions/3211991/does-ie-8-have-a-limit-on-number-of-stylesheets-per-page
http://blogs.telerik.com/aspnetmvcteam/posts/10-05-03/internet-explorer-css-limits.aspx
分享到:
相关推荐
CSS——Cascading Style Sheets 层叠样式表 作用 定义了HTML元素怎样去显示 一般存储在样式表中 也可以存储在外部样式文件.css文件中
标题“IE对style的限制”涉及的是在Internet Explorer(IE)浏览器中,对CSS(Cascading Style Sheets)样式表的一些特性和应用的特定限制。这些限制主要与IE的兼容性问题、旧版本的渲染引擎以及它对某些CSS属性的...
CSS 指层叠样式表 (Cascading Style Sheets) 样式定义如何显示 HTML 元素 样式通常存储在样式表中 把样式添加到 HTML 4.0 中,是为了解决内容与表现分离的问题 外部样式表可以极大提高工作效率 外部样式表通常...
Cascading Style Sheets: Designing for the Web, Third Edition By Håkon Wium Lie, Bert Bos ............................................... Publisher: Addison Wesley Professional Pub Date: April...
closure-stylesheets, lints,优化和 i18n izes的CSS transpiler 关闭样式表闭包样式表是对CSS的扩展,它向标准 CSS conditionals conditionals conditionals conditionals conditionals conditionals conditionals
随着移动设备的普及,CSS还支持响应式设计(Responsive Web Design),通过媒体查询(Media Queries)等手段,使得网页可以根据设备屏幕尺寸自动调整布局和样式,提供良好的跨设备浏览体验。 综上所述,CSS作为网页...
- **`document.styleSheets[0].rules`**:主要用于Internet Explorer浏览器,按照选择器数量计数。 - **`document.styleSheets[0].cssRules`**:适用于现代浏览器,按照CSS规则数量计数,更加标准化。 在实际开发中...
在判断出是IE6或IE7之后,通过修改document.styleSheets数组中的第一个样式表(styleSheets[0])的href属性来加载特定的CSS文件。这是实现不同浏览器加载不同样式表的关键步骤。 在实际应用中,我们可能会遇到需要...
StyleSheets_for_PyQt5_Designer_Templates_CSS_,_QSS_StyleSheets-for-PyQt5
`matplotlib-stylesheets` 是一个 Python 库,专为 Matplotlib,这是一个流行的 Python 数据可视化库,提供了丰富的样式表资源。这个库允许开发者轻松地应用预定义的样式到他们的图表,使得数据可视化的外观更加专业...
Using a standardized approach to CSS in an example-packed, step-by-step format, this comprehensive introduction clearly shows you how to combine CSS with HTML, XHTML, or XML to create rich, ...
Using a standardized approach to CSS in an example-packed, step-by-step format, this comprehensive introduction clearly shows you how to combine CSS with HTML, XHTML, or XML to create rich, ...
Cascading Style Sheets for Web Design Second Edition
Cascading Style Sheets for Web Design Second Edition Psrt2
CSS,全称为Cascading Style Sheets,即层叠样式表,是一种用于控制网页布局和外观的语言。它与HTML语言结合使用,能够实现内容与样式的分离,使网页设计更加灵活、高效。通过CSS,设计师可以精细地调整文本的字体、...
#Stylesheets是社区生成的最佳CSS资源的集合。 创建它是为了让Web设计社区可以共享和分类所有可以找到的最佳工具,教程,代码片段和存储库。 您可以发布与CSS相关的任何内容,并让社区“加注星标”,以使其他人知道...
Beginning CSS: Cascading Style Sheets for Web Design, Second Edition
首先,请确保您已经创建了Rails应用程序 rails new APP_NAME ... rm -rf app/assets/stylesheets curl -L https://github.com/ubi-legal-innovation-team/rails-stylesheets/archive/master.zip > styleshee