標籤:style http color width art html
Html代碼
- <html>
- <head>
- <title>testCSS</title>
- <style type="text/css">
- h2{
- color:red;
- }
- h2{
- color:green;
- }
- h3{
- color:red;
- }
- h5{
- color:green;
- }
- </style>
- <link rel="stylesheet" type="text/css" href="a.css" />
- </head>
- <body>
- <h1 style="color:red;color:green">1.綠色,當內聯的方式定義color:red;color:green,以後面的為準,後面會把前面的覆蓋</h1>
- <h2 >2.綠色,當內聯的方式定義兩次顏色,以後面的為準,後面會把前面的覆蓋</h2>
- <h3 style="color:green">3.當以內聯和內部樣式表的方式定義,內聯優先於內部樣式表</h3>
- <h4 style="color:green">4.當以內聯和內部樣式表的方式定義,內聯優先於內部樣式表,與內部樣式表存放的位置無關</h3>
- <h5>5.當內部樣式表和外部樣式表同時定義時,與內聯樣式與外部樣式表定義的順序有關,以後面為準,後面會把前面的覆蓋</h5>
- </body>
- <style type="text/css">
- h4{
- color:red;
- }
- </style>
-
-
- </html>
執行結果:
Html代碼
- <html>
- <head>
- <title>testCSS</title>
- <style type="text/css">
- h1{
- color:green;
- }
- #h1id{
- color:blue;
- }
- .h1class{
- color:yellow;
- }
-
- #h2id h2{
- color:blue;
- }
- .h2class h2{
- color:yellow
- }
- div h2{
- color:red;
- }
- </style>
- </head>
- <body>
- 一、內聯>>id選取器>>類別選取器>>標籤選取器 >>:表示優先的意思 <br>
- <h1 style="color:red" id="h1id" class="h1class">1.紅色 內聯、標籤選取器、類別選取器、id選取器都符合,優先內聯</h1>
- <h1 style="" id="h1id" class="h1class">2.藍色 標籤選取器、類別選取器、id選取器都符合,優先id選取器</h1>
- <h1 style="" class="h1class">3.黃色 標籤選取器、類別選取器都符合,優先類別選取器</h1>
- <h1 style="" >4.綠色 最終才是標籤選取器</h1>
- 二、派生選取器依然遵守上面的規律 id派生>>類派生 >>標籤派生
- <div id="h2id" class="h2class"><h2>1.藍色</h2></div>
- <div class="h2class"><h2>2.黃色</h2></div>
- <div ><h2>3.紅色</h2></div>
- </body>
-
-
-
- </html>