css 之優先策略

來源:互聯網
上載者:User

標籤:style   http   color   width   art   html   

Html代碼  
  1. <html>  
  2.     <head>  
  3.        <title>testCSS</title>            
  4.        <style type="text/css">  
  5.           h2{  
  6.                 color:red;  
  7.           }  
  8.         h2{  
  9.             color:green;  
  10.         }  
  11.         h3{  
  12.            color:red;  
  13.         }  
  14.         h5{  
  15.             color:green;  
  16.         }  
  17.         </style>  
  18.         <link rel="stylesheet" type="text/css" href="a.css" />  
  19.     </head>  
  20.     <body>  
  21.             <h1 style="color:red;color:green">1.綠色,當內聯的方式定義color:red;color:green,以後面的為準,後面會把前面的覆蓋</h1>  
  22.             <h2 >2.綠色,當內聯的方式定義兩次顏色,以後面的為準,後面會把前面的覆蓋</h2>  
  23.             <h3 style="color:green">3.當以內聯和內部樣式表的方式定義,內聯優先於內部樣式表</h3>  
  24.             <h4 style="color:green">4.當以內聯和內部樣式表的方式定義,內聯優先於內部樣式表,與內部樣式表存放的位置無關</h3>  
  25.             <h5>5.當內部樣式表和外部樣式表同時定義時,與內聯樣式與外部樣式表定義的順序有關,以後面為準,後面會把前面的覆蓋</h5>  
  26.     </body>  
  27.     <style type="text/css">          
  28.         h4{  
  29.            color:red;  
  30.         }  
  31.         </style>  
  32.            
  33.   
  34. </html>  

 執行結果:

 

Html代碼  
  1. <html>  
  2.     <head>  
  3.        <title>testCSS</title>            
  4.        <style type="text/css">  
  5.           h1{  
  6.              color:green;  
  7.           }  
  8.           #h1id{  
  9.              color:blue;  
  10.           }  
  11.           .h1class{  
  12.              color:yellow;          
  13.           }  
  14.             
  15.           #h2id h2{  
  16.              color:blue;  
  17.           }  
  18.           .h2class h2{  
  19.               color:yellow  
  20.           }  
  21.           div h2{  
  22.              color:red;  
  23.           }  
  24.         </style>  
  25.     </head>  
  26.     <body>  
  27.            一、內聯>>id選取器>>類別選取器>>標籤選取器   >>:表示優先的意思   <br>  
  28.             <h1 style="color:red" id="h1id" class="h1class">1.紅色 內聯、標籤選取器、類別選取器、id選取器都符合,優先內聯</h1>  
  29.             <h1 style="" id="h1id" class="h1class">2.藍色 標籤選取器、類別選取器、id選取器都符合,優先id選取器</h1>  
  30.              <h1 style=""  class="h1class">3.黃色 標籤選取器、類別選取器都符合,優先類別選取器</h1>  
  31.              <h1 style="" >4.綠色 最終才是標籤選取器</h1>  
  32.            二、派生選取器依然遵守上面的規律  id派生>>類派生 >>標籤派生   
  33.               <div id="h2id" class="h2class"><h2>1.藍色</h2></div>  
  34.               <div           class="h2class"><h2>2.黃色</h2></div>  
  35.               <div                          ><h2>3.紅色</h2></div>  
  36.     </body>  
  37.       
  38.            
  39.   
  40. </html>  

  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.