*[class = name] {
/* 相關設定 */
}name 為自訂的類別名稱,由於很常用,因此可用小數點 . 直接加 name ,例如
.name {
/* 相關設定 */
}如此便是通用的類別選取器,可以使用在任何元素裡頭,舉例如下
.red {
color: red;
}
.green {
color: green;
}
.navy {
color: navy;
}
.blue {
color: blue;
}
/* 《程式語言教學誌》的範例程式
http://pydoing.blogspot.com/
檔名:demo26.css
功能:示範 CSS 2.1 樣式表的使用
作者:張凱慶
時間:西元 2011 年 7 月 */我們以下面的 HTML 文件載入
<html>
<head>
<title>網頁標題</title>
<link rel="stylesheet" type="text/css"
href="demo26.css">
</head>
<body>
You ever have that feeling where you're not sure if
you're awake or still dreaming?
<div class="red">Free your mind.</div>
<span class="green">Believe the unbelievable.</span>
<blockquote class="navy">There is no spoon.</blockquote>
<p class="blue">Because I choose to.</p>
</body>
</html>
<!-- 《程式語言教學誌》的範例程式
http://pydoing.blogspot.com/
檔名:demo26.html
功能:示範 CSS 2.1 樣式表的使用
作者:張凱慶
時間:西元 2011 年 7 月 -->瀏覽器 (broswer) 開啟如下

類別選取器也可以設定成元素專有,這時在小數點前加上元素名稱即可,例如
div.red {
color: red;
}
div.green {
color: green;
}
div.navy {
color: navy;
}
div.blue {
color: blue;
}
/* 《程式語言教學誌》的範例程式
http://pydoing.blogspot.com/
檔名:demo27.css
功能:示範 CSS 2.1 樣式表的使用
作者:張凱慶
時間:西元 2011 年 7 月 */我們以下面的 HTML 文件載入
<html>
<head>
<title>網頁標題</title>
<link rel="stylesheet" type="text/css"
href="demo27.css">
</head>
<body>
You ever have that feeling where you're not sure if
you're awake or still dreaming?
<div class="red">Free your mind.</div>
<span class="green">Believe the unbelievable.</span>
<blockquote class="navy">There is no spoon.</blockquote>
<p class="blue">Because I choose to.</p>
</body>
</html>
<!-- 《程式語言教學誌》的範例程式
http://pydoing.blogspot.com/
檔名:demo27.html
功能:示範 CSS 2.1 樣式表的使用
作者:張凱慶
時間:西元 2011 年 7 月 -->瀏覽器開啟如下

可以看見只有 <div> 元素內的文字改變顏色。
| 中英文術語對照 | |
|---|---|
| 類別選取器 | class selector |
| 屬性選取器 | attribute selector |
| 屬性 | attribute |
| 瀏覽器 | 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
沒有留言:
張貼留言