註解中可以是任何附加說明的文字,對定義的樣式 (style) 規則 (rule) 不會有任何影響,例如
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | /* p 元素的 demo 類別 */ p.demo { /* 白色文字 */ color : white ; /* 黑色背景 */ background-color : black ; } /* 《程式語言教學誌》的範例程式 檔名:demo04.css 功能:示範 CSS 2.1 樣式表的使用 作者:張凱慶 時間:西元 2011 年 7 月 */ |
我們以下面的 HTML 文件載入 demo04.css
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | < html > < head > < title >網頁標題</ title > < link rel = "stylesheet" type = "text/css" href = "demo04.css" > </ head > < body > < p class = "demo" > 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 class = "demo" > Free your mind.</ p > < p >Believe the unbelievable.</ p > < p class = "demo" > There is no spoon.</ p > < p >I can only show you the door, you have to walk through it.</ p > < p class = "demo" > Choice. The problem is choice.</ p > < p >Then tomorrow we may all be dead, but how would that be different from any other day?</ p > < p class = "demo" > I have dreamed a dream, but now that dream has gone from me.</ p > < p >Choice is an illusion, created between those with power, and those without.</ p > < p class = "demo" > Because I choose to.</ p > < p >Everything that has a beginning has an end.</ p > </ body > </ html > <!-- 《程式語言教學誌》的範例程式 檔名:demo04.html 功能:示範 CSS 2.1 樣式表的使用 作者:張凱慶 時間:西元 2011 年 7 月 --> |
瀏覽器 (broswer) 開啟如下

註解可以出現在任何地方,也可以跨行,但是註解不可是巢狀的,也就是註解中不可以有另一個註解,例如
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | /* p 元素的 demo 類別 */ p.demo { /* 白色文字 /* 巢狀註解 */ */ color : white ; /* 黑色背景 */ background-color : black ; } /* 《程式語言教學誌》的範例程式 檔名:demo04.css 功能:示範 CSS 2.1 樣式表的使用 作者:張凱慶 時間:西元 2011 年 7 月 */ |
因為第一個 /* 碰到第一個 */ 就會結束註解的效力範圍,第二個 /* 會是註解的內容,後面會多一個 */ 出來,瀏覽器 可能會有各自的解讀方式,例如以下的 HTML 文件載入 demo04.css
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | < html > < head > < title >網頁標題</ title > < link rel = "stylesheet" type = "text/css" href = "demo05.css" > </ head > < body > < p class = "demo" > 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 class = "demo" > Free your mind.</ p > < p >Believe the unbelievable.</ p > < p class = "demo" > There is no spoon.</ p > < p >I can only show you the door, you have to walk through it.</ p > < p class = "demo" > Choice. The problem is choice.</ p > < p >Then tomorrow we may all be dead, but how would that be different from any other day?</ p > < p class = "demo" > I have dreamed a dream, but now that dream has gone from me.</ p > < p >Choice is an illusion, created between those with power, and those without.</ p > < p class = "demo" > Because I choose to.</ p > < p >Everything that has a beginning has an end.</ p > </ body > </ html > <!-- 《程式語言教學誌》的範例程式 檔名:demo05.html 功能:示範 CSS 2.1 樣式表的使用 作者:張凱慶 時間:西元 2011 年 7 月 --> |
結果如下

我們可以看到後面的 */ 破壞
color: white
的規則。 中英文術語對照 | |
---|---|
註解 | comment |
C 語言 | C programming language |
樣式 | style |
規則 | rule |
瀏覽器 | broswer |
您可以繼續參考
基本概念
單位
選取器
@import 規則
階層
元素呈現方式 display
相關目錄
CSS 2.1 快速導覽
HTML, CSS 教材
首頁
參考資料
http://www.w3.org/TR/CSS21/syndata.html
https://developer.mozilla.org/en/CSS/Comments
沒有留言:
張貼留言