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

書寫CSS時需要的七個方面

開發(fā) 前端
隨著CSS網(wǎng)頁布局的應用越來越廣泛,更多的CSSer開始書寫CSS,本文向大家描述一下書寫CSS時應該注意的七個方面,希望對你的學習有所幫助。

本文向大家描述一下書寫CSS時注意的七個方面,如何才能寫出高效規(guī)范的CSS代碼呢,這里就和大家分享一下。

書寫CSS時注意的七個方面

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

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

◆不推薦使用行間樣式

XML/HTML代碼 

  1.  
  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; charset=utf-8" />     
  6. <title>Page title - book.chinaz.comtitle>     
  7. head>       
  8. <body>     
  9. <p style="color: red"> ... p>       
  10. body>       
  11. html>   
  12.  

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

XML/HTML代碼 

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

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

XML/HTML代碼 

  1.  
  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.comtitle>       
  7. <link rel="stylesheet" href="name.css" type="text/css" media="screen" />       
  8. < /head>       
  9. <body> ... body>       
  10. html>     
  11.  

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

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

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

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

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

◆不推薦@import導入方式

XML/HTML代碼 

  1.  
  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 - 52css.comtitle>       
  7. <style type="text/css" media="screen">       
  8. @import url("styles.css");      
  9. style>     
  10. head>     
  11. <body> ... body>     
  12. html>     
  13.  

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

XML/HTML代碼 

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

 三、使用繼承

低效率的

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.  

譯者注: 對于十六進制顏色值,個人偏向于色值不縮寫且英文字母要大寫的方式.

高效的

CSS代碼 

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

#p#六、使用簡記屬性

低效率的

CSS代碼 

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

高效的

CSS代碼 

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

 七、避免使用 !important

慎用寫法

CSS代碼 

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

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

CSS代碼 

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

【編輯推薦】

  1. 八大技巧輕松書寫CSS
  2. DIV+CSS網(wǎng)頁布局的五大特點
  3. DIV CSS隱藏內(nèi)容樣式方法詳解
  4. CSS兼容:解決IE6、IE7和IE8的兼容問題妙招
  5. DIV CSS網(wǎng)頁布局需要掌握的八大技巧

 

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

2010-09-01 09:39:07

CSS

2010-09-09 17:06:12

CSS

2022-10-11 07:20:56

YAML字符串語言

2023-03-29 18:40:00

2023-08-01 10:41:27

分派IT工作CIO

2023-01-31 08:00:00

開源開發(fā)軟件

2022-03-18 08:23:43

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

2022-06-27 14:03:06

IT治理首席信息官

2023-05-06 10:50:41

IT培訓IT團隊

2021-09-02 18:34:36

云原生架構(gòu)服務化

2023-08-22 10:25:19

CSS動畫網(wǎng)頁

2025-07-21 00:01:00

2022-11-21 08:54:25

IT對接業(yè)務

2021-12-21 11:16:04

云計算云計算環(huán)境云應用

2021-11-30 13:59:22

數(shù)據(jù)治理大數(shù)據(jù)數(shù)據(jù)分析

2020-03-23 10:59:52

CISO網(wǎng)絡安全漏洞

2023-01-05 14:58:54

2011-04-06 15:34:45

活動目錄

2022-01-11 10:50:35

數(shù)據(jù)治理CIOIT領(lǐng)導
點贊
收藏

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