CSS實現了網頁內容和網頁效果的徹底分離。
內聯樣式表(在標籤內設元素的樣式)
1
<p style="background-color:yellow; font-size:xx-large">今天天氣真好呀!</p>
“內聯樣式表”優先級比”嵌入樣式表”高
嵌入樣式表(需要在head標籤內寫<style type="text/css"></style>)
1
2
3
4
5
6
7
<!--需要在head標籤內寫-->
<style type="text/css">
p {
background-color: lightpink;
font-size: x-large;
}
</style>
“內聯樣式表”優先級比”嵌入樣式表”高
外部樣式表link
連結外部的樣式檔(寫在head裡)
1
2
<!--外部樣式表link-->
<link href="TestStyleSheet.css" rel="stylesheet" />
完整HTML碼
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<!-- 3.外部樣式表link-->
<link href="TestStyleSheet.css" rel="stylesheet" />
<!-- 2.嵌入樣式表: 需要在head標籤內寫-->
<style type="text/css">
p {
background-color: lightpink;
font-size: x-large;
}
</style>
</head>
<body>
<!-- 1."內聯樣式表"優先級比"嵌入樣式表"高-->
<p style="background-color:yellow; font-size:xx-large">今天天氣真好呀!</p>
<p>今天天氣真好呀!</p>
<p>今天天氣真好呀!</p>
<p>今天天氣真好呀!</p>
<tt>Hello,你好嗎?今天天氣真好呀!</tt>
</body>
</html>
TestStyleSheet.css
1
2
3
4
5
6
7
8
tt {
background-color:greenyellow;
font-size:xx-large;
}
p {
background-color: lightblue;
font-size: large;
}