<h1 style="color:blue;margin-left:30px;">This is a heading</h1>Internal Style Sheet 在文件<head></head>裡使用<style></style>定義
<!DOCTYPE html>
<html lang="en">
<head>
<style>
h1 {
color: blue;
margin-left: 30px;
}
</style>
</head>
<body>
....
<h1>This is a heading</h1>
</body>
</html>External Style Sheet 假設網頁資料匣結構如下
├── css/
| └── mystyle.css
└── index.html
其中index.html為網頁檔。
mystyle.css為文字檔包含以下句子:
h1 {
color: blue;
margin-left: 30px;
}
index.html包含以下句子:
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="css/mystyle.css">
</head>
<body>
...
<h1>This is a heading</h1>
...
</body>
</html>假設整個網「站」資料儲存結構如下
├── assets/
| ├── style1.css
| └── css/
| ├── page2.html
| └── style2.css
├── style3.css
└── page1.html
從網頁檔所在位置出發
從網「站」「根」目錄出發: 使用/開始
從網頁檔的「上個」目錄出發: 使用../開始
style="margin:auto;"。style="display:block;"轉區塊,或用區塊標籤(如<div>)。選出某個class:
.right {
...
}
使用時<標籤 class="right">...</標籤>
選出網「頁」中某個唯一的id:
#contactus {
...
}
會被用在該網「頁」檔中唯一有<標籤 id="contactus">...</標籤>的地方
A、B兩元素全部適用:
div, p {
...
}
.title, .head1 {
...
}A、B兩元素, 只有當B元素是A的descendant(後代) element時適用:(沒有逗號)
div p {
...
}
.title .head1 {
...
}