偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

專家提醒 編寫(xiě)CSS時(shí)注意的七個(gè)方面

開(kāi)發(fā) 前端
本文和大家重點(diǎn)學(xué)習(xí)一下編寫(xiě)CSS時(shí)注意的七個(gè)方面,隨著CSS網(wǎng)頁(yè)布局的應(yīng)用越來(lái)越廣泛,更多的CSSer開(kāi)始書(shū)寫(xiě)CSS,如何才能寫(xiě)出高效規(guī)范的CSS代碼才是問(wèn)題的關(guān)鍵。

隨著CSS網(wǎng)頁(yè)布局的應(yīng)用越來(lái)越廣泛,但是如何才能寫(xiě)出高效規(guī)范的CSS代碼呢,這里向大家描述一下編寫(xiě)CSS時(shí)注意的七個(gè)方面,主要包括使用外聯(lián)樣式替代行間樣式或者內(nèi)嵌樣式,建議使用 link 引入外部樣式表等內(nèi)容。

編寫(xiě)CSS時(shí)注意的七個(gè)方面

隨著CSS網(wǎng)頁(yè)布局的應(yīng)用越來(lái)越廣泛,更多的CSSer開(kāi)始書(shū)寫(xiě)CSS,如何才能寫(xiě)出高效規(guī)范的CSS代碼呢,今天向大家介紹,必須要注意的七個(gè)方面:

一、使用外聯(lián)樣式替代行間樣式或者內(nèi)嵌樣式

◆不推薦使用行間樣式

XML/HTML代碼 

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">     
  3. <html xmlns="http://www.w3.org/1999/xhtml">     
  4. <head>     
  5. <meta http-equiv="Content-Type" content="text/html;
  6.  charset=utf-8" />     
  7. <title>Page title - book.chinaz.com</title>     
  8. </head>       
  9. <body>     
  10. <p style="color: red"> ... </p>       
  11. </body>       
  12. </html>   
  13.  

 ◆不推薦使用內(nèi)嵌樣式

XML/HTML代碼 

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"   
  2. "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en">       
  3. <head>     
  4. <meta http-equiv="Content-Type" content="text/html; 
  5. charset=utf-8" />     
  6. <title>Page title - book.chinaz.com</title>       
  7. <style type="text/css" media="screen">     
  8. p { color: red; }       
  9. </style>       
  10. </head>       
  11. <body>... </body>       
  12. </html>     
  13.  

 ◆推薦使用外聯(lián)樣式

XML/HTML代碼 

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"   
  2. "http://www.w3.org/TR/html4/strict.dtd">     
  3. <html lang="en">     
  4. <head>       
  5. <meta http-equiv="content-type" content="text       
  6. <title>Page title - book.chinaz.com</title>       
  7. <link rel="stylesheet" href="name.css"
  8.  type="text/css" media="screen" />       
  9. < /head>       
  10. <body> ... </body>       
  11. </html>     
  12.  

 #p#二、建議使用 link 引入外部樣式表

為了兼容老版本的瀏覽器,建議使用 link 引入外部樣式表的方來(lái)代替 @import導(dǎo)入樣式的方式.

譯者注: @import是CSS2.1提出的所以老的瀏覽器不支持。

@import和link在使用上會(huì)有一些區(qū)別, 利用二者之間的差異,可以在實(shí)際運(yùn)用中進(jìn)行權(quán)衡。

關(guān)于@import和link方式的比較在52CSS.com上有幾篇文章可以拓展閱讀。

◆不推薦@import導(dǎo)入方式

XML/HTML代碼 

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"  
  2.  
  3.  "http://www.w3.org/TR/html4/strict.dtd">       
  4. <html lang="en">     
  5. <head>       
  6. <meta http-equiv="content-type" content="text       
  7. <title>Page title - 52css.com</title>       
  8. <style type="text/css" media="screen">       
  9. @import url("styles.css");      
  10. </style>     
  11. </head>     
  12. <body> ... </body>     
  13. </html>     
  14.  

 ◆推薦引入外部樣式表方式

XML/HTML代碼 

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"   
  2. "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> 
  3. <head>     
  4. <meta http-equiv="content-type" content="text       
  5. <title>Page title - blog.huangchao.org</title>     
  6. <link rel="stylesheet" href="name.css" type="text/css" 
  7. media="screen" />     
  8. </head>       
  9. <body> ... </body>       
  10. </html>     
  11.  

 三、使用繼承

低效率的

CSS代碼 

  1. p{ font-family: arial, helvetica, sans-serif; }      
  2. #container { font-family: arial, helvetica, sans-serif; }      
  3. #navigation { font-family: arial, helvetica, sans-serif; }      
  4. #content { font-family: arial, helvetica, sans-serif; }      
  5. #sidebar { font-family: arial, helvetica, sans-serif; }      
  6. h1 { font-family: georgia, times, serif; }      
  7.  

高效的

CSS代碼 

  1. body { font-family: arial, helvetica, sans-serif; }       
  2. body { font-family: arial, helvetica, sans-serif; }      
  3. h1 { font-family: georgia, times, serif; }   
  4.  

 #p#四、使用多重選擇器

低效率的

CSS代碼 

  1. h1 { color: #236799; }       
  2. h2 { color: #236799; }      
  3. h3 { color: #236799; }      
  4. h4 { color: #236799; }    
  5.  

高效的

CSS代碼 

  1. h1, h2, h3, h4 { color: #236799; }    
  2.  

五、使用多重聲明

低效率的

CSS代碼 

  1. p { margin: 0 0 1em; }      
  2. p { background: #ddd; }      
  3. p { color: #666; }     
  4.  

譯者注: 對(duì)于十六進(jìn)制顏色值,個(gè)人偏向于色值不縮寫(xiě)且英文字母要大寫(xiě)的方式.

高效的

CSS代碼 

  1. p { margin: 0 0 1em; background: #ddd; color: #666; }  
  2.  
  3.    

#p#六、使用簡(jiǎn)記屬性

低效率的

CSS代碼 

  1. body { font-size: 85%; font-family: arial, helvetica, sans-serif;   
  2. background-image: url(image.gif); background-repeat: no-repeat;   
  3. background-position: 0 100%; margin-top: 1em; margin-right: 1em;   
  4. margin-bottom: 0; margin-left: 1em; padding-top: 10px;   
  5. padding-right: 10px; padding-bottom: 10px; padding-left: 10px;  
  6.  border-style: solid; border-width: 1px;   
  7. border-color: red; color: #222222;     
  8.  

 高效的

CSS代碼 

  1. body { font: 85% arial, helvetica, sans-serif;   
  2. background: url(image.gif) no-repeat 0 100%;   
  3. margin: 1em 1em 0; padding: 10px;   
  4. border: 1px solid red; color: #222; }    
  5.  

七、避免使用 !important

慎用寫(xiě)法

CSS代碼 

  1. #news { background: #ddd !important; }     
  2.  

特定情況下可以使用以下方式提高權(quán)重級(jí)別

CSS代碼 

  1. #container #news { background: #ddd; }      
  2. body #container #news { background: #ddd; }    
  3.  

【編輯推薦】

  1. clear屬性在CSS中的妙用
  2. JavaScript動(dòng)態(tài)創(chuàng)建div屬性和樣式
  3. 14大CSS工具提高網(wǎng)頁(yè)設(shè)計(jì)效率
  4. 五大CSS3新技術(shù)用法指導(dǎo)
  5. 解讀DIV CSS網(wǎng)頁(yè)布局中CSS無(wú)效十個(gè)原因

 

責(zé)任編輯:佚名 來(lái)源: css3-html5.com
相關(guān)推薦

2010-09-01 09:39:07

CSS

2010-08-30 13:38:10

CSS

2010-06-04 14:42:25

2010-06-01 10:37:15

SVN合并

2023-03-29 18:40:00

2018-10-16 15:12:48

2018-10-18 11:03:06

2017-07-28 14:43:49

大數(shù)據(jù)數(shù)據(jù)可視化秘密

2010-05-26 17:05:13

SVN提交

2022-03-18 08:23:43

人工智能神經(jīng)網(wǎng)絡(luò)失敗

2023-08-01 10:41:27

分派IT工作CIO

2022-06-27 14:03:06

IT治理首席信息官

2011-06-01 09:27:08

JavaScript

2011-01-11 08:45:17

JavaScript

2019-07-10 11:35:46

防火墻技術(shù)云計(jì)算

2010-08-12 09:39:26

FlexaddChil

2023-08-22 10:25:19

CSS動(dòng)畫(huà)網(wǎng)頁(yè)

2025-07-21 00:01:00

2016-12-13 10:06:25

編寫(xiě)Java單元測(cè)試技巧
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)