0 Comments

书写高效CSS注意的七个方面(2)

发布于:2013-07-18  |   作者:广州网站建设  |   已聚集:人围观
二、建议使用link引入外部样式表

 

为了兼容老版本的浏览器,建议使用link引入外部样式表的方来代替@import导入样式的方式.

译者注:@import是CSS2.1提出的所以老的浏览器不支持,点击查看@import的兼容性。

@import和link在使用上会有一些区别,利用二者之间的差异,可以在实际运用中进行权衡。

关于@import和link方式的比较在52CSS.com上有几篇文章可以拓展阅读。

不推荐@import导入方式

ExampleSourceCode
广州网站建设,网站建设,广州网页设计,广州网站设计


  1.  
  2.  
  3. "http://www.w3.org/TR/html4/strict.dtd"> 
  4. <htmllanghtmllang="en"> 
  5. <head> 
  6. <metahttp-equivmetahttp-equiv="content-type"content="text  
  7. <title>Pagetitle-52css.comtitle> 
  8. <styletypestyletype="text/css"media="screen"> 
  9. @importurl("styles.css");  
  10. style> 
  11. head> 
  12. <body>...body> 
  13. html> 
  14.  

推荐引入外部样式表方式

ExampleSourceCode


  1.  
  2. "http://www.w3.org/TR/html4/strict.dtd"><htmllanghtmllang="en"><head> 
  3. <metahttp-equivmetahttp-equiv="content-type"content="text  
  4. <title>Pagetitle-52css.comtitle> 
  5. <linkrellinkrel="stylesheet"href="name.css"type="text/css"media="screen"/> 
  6. head> 
  7. <body>...body> 
  8. html> 
  9.  

三、使用继承

ExampleSourceCode


  1. 低效率的  
  2.  
  3. p{font-family:arial,helvetica,sans-serif;}  
  4. #container{font-family:arial,helvetica,sans-serif;}  
  5. #navigation{font-family:arial,helvetica,sans-serif;}  
  6. #content{font-family:arial,helvetica,sans-serif;}  
  7. #sidebar{font-family:arial,helvetica,sans-serif;}  
  8. h1{font-family:georgia,times,serif;}  
  9.  
  10. 高效的  
  11.  
  12. body{font-family:arial,helvetica,sans-serif;}  
  13. body{font-family:arial,helvetica,sans-serif;}  
  14. h1{font-family:georgia,times,serif;}  
飞机