這就是利用逗號 , 分開不同的標籤,也就是把每個選取項 (selector) 以逗號分開,如下例
p, div, blockquote { color: white; background-color: black; } /* 《程式語言教學誌》的範例程式 http://pydoing.blogspot.com/ 檔名:demo07.css 功能:示範 CSS 2.1 樣式表的使用 作者:張凱慶 時間:西元 2011 年 7 月 */
此例中將 <p> 、 <div> 、 <blockquote> 三種 HTML 元素 (element) 都設定為黑底白字,我們以下面的 HTML 文件載入 demo07.css
<html> <head> <title>網頁標題</title> <link rel="stylesheet" type="text/css" href="demo07.css"> </head> <body> <p>You ever have that feeling where you're not sure if you're awake or still dreaming?</p> <p>A prison for your mind.</p> <p>Free your mind.</p> <p>Believe the unbelievable.</p> <div>There is no spoon.</div> <div>I can only show you the door, you have to walk through it.</div> <div>Choice. The problem is choice.</div> <div>Then tomorrow we may all be dead, but how would that be different from any other day?</div> <blockquote>I have dreamed a dream, but now that dream has gone from me.</blockquote> <blockquote>Choice is an illusion, created between those with power, and those without.</blockquote> <blockquote>Because I choose to.</blockquote> <blockquote>Everything that has a beginning has an end.</blockquote> </body> </html> <!-- 《程式語言教學誌》的範例程式 http://pydoing.blogspot.com/ 檔名:demo07.html 功能:示範 CSS 2.1 樣式表的使用 作者:張凱慶 時間:西元 2011 年 7 月 -->
瀏覽器 (broswer) 開啟如下
如果不用群組的寫法,就得逐一給每個標籤進行相同的樣式 (style) 定義,例如
p { color: white; background-color: black; } div { color: white; background-color: black; } blockquote { color: white; background-color: black; } /* 《程式語言教學誌》的範例程式 http://pydoing.blogspot.com/ 檔名:demo08.css 功能:示範 CSS 2.1 樣式表的使用 作者:張凱慶 時間:西元 2011 年 7 月 */
我們以下面的 HTML 文件載入 demo08.css
<html> <head> <title>網頁標題</title> <link rel="stylesheet" type="text/css" href="demo08.css"> </head> <body> <p>You ever have that feeling where you're not sure if you're awake or still dreaming?</p> <p>A prison for your mind.</p> <p>Free your mind.</p> <p>Believe the unbelievable.</p> <div>There is no spoon.</div> <div>I can only show you the door, you have to walk through it.</div> <div>Choice. The problem is choice.</div> <div>Then tomorrow we may all be dead, but how would that be different from any other day?</div> <blockquote>I have dreamed a dream, but now that dream has gone from me.</blockquote> <blockquote>Choice is an illusion, created between those with power, and those without.</blockquote> <blockquote>Because I choose to.</blockquote> <blockquote>Everything that has a beginning has an end.</blockquote> </body> </html> <!-- 《程式語言教學誌》的範例程式 http://pydoing.blogspot.com/ 檔名:demo08.html 功能:示範 CSS 2.1 樣式表的使用 作者:張凱慶 時間:西元 2011 年 7 月 -->
這兩份 HTML 文件的外觀是一樣的
中英文術語對照 | |
---|---|
標籤 | tag |
規則 | rule |
群組 | grouping |
選取器 | selector |
元素 | element |
瀏覽器 | broswer |
樣式 | style |
您可以繼續參考
基本概念
單位
選取器
@import 規則
階層
元素呈現方式 display
相關目錄
CSS 2.1 快速導覽
HTML, CSS 教材
首頁
參考資料
http://www.w3.org/TR/CSS21/syndata.html
http://www.w3.org/TR/CSS21/selector.html
沒有留言:
張貼留言