1,寫在元素標籤的style屬性中,僅對當前元素有效;
2,寫在當前頁面頭部的標籤中,僅對當前頁面所有元素有效;
3,寫在獨立的CSS文件中,對所有引入該文件的頁面均有效。
下面我們用例子來一一說明:
寫在元素標籤的style屬性中:
<p style="color:red;">abc</p>
寫在當前頁面頭部的標籤中:
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
p{
text-align: center;
}
</style>
</head>
寫在獨立的CSS文件中:
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="Untitled-1.css">
</head>
下面是CSS獨立文件中的內容:
p{
color: red;
}