[id = name] {
/* 相關設定 */
}name 為自訂的 ID 名稱,可用井字號 # 直接加 name ,例如
#name {
/* 相關設定 */
}這邊須注意,因為每一個 HTML 元素 (element) 的 id 屬性都是專屬的識別碼,因此 ID 選取器設定的樣式 (style) 也是專屬於該元素。
舉例如下
#red {
color: red;
}
#green {
color: green;
}
#navy {
color: navy;
}
#blue {
color: blue;
}
/* 《程式語言教學誌》的範例程式
http://pydoing.blogspot.com/
檔名:demo28.css
功能:示範 CSS 2.1 樣式表的使用
作者:張凱慶
時間:西元 2011 年 7 月 */我們以下面的 HTML 文件載入
<html>
<head>
<title>網頁標題</title>
<link rel="stylesheet" type="text/css"
href="demo28.css">
</head>
<body>
You ever have that feeling where you're not sure if
you're awake or still dreaming?
<div id="red">Free your mind.</div>
<span id="green">Believe the unbelievable.</span>
<blockquote id="navy">There is no spoon.</blockquote>
<p id="blue">Because I choose to.</p>
</body>
</html>
<!-- 《程式語言教學誌》的範例程式
http://pydoing.blogspot.com/
檔名:demo28.html
功能:示範 CSS 2.1 樣式表的使用
作者:張凱慶
時間:西元 2011 年 7 月 -->瀏覽器 (broswer) 開啟如下

| 中英文術語對照 | |
|---|---|
| ID 選取器 | ID selector |
| 屬性選取器 | attribute selector |
| 屬性 | attribute |
| 元素 | element |
| 樣式 | style |
| 瀏覽器 | broswer |
您可以繼續參考
基本概念
單位
選取器
@import 規則
階層
元素呈現方式 display
相關目錄
CSS 2.1 快速導覽
HTML, CSS 教材
首頁
參考資料
http://www.w3.org/TR/CSS21/selector.html
https://developer.mozilla.org/en/CSS/Getting_Started/Selectors
沒有留言:
張貼留言