HTML CSS(v1) Style 的優先次序@ 傑克! 真是太神奇了! :: 痞客邦 | css important教學
快速參考:常見的CSS(v1)selector設定套用的次序如下:
常見的 CSS(v1) selector 設定套用的次序如下:
<style type="text/css"> div { color: black ; ... } .nClass { color: green ; ... } #nId { color: blue ; ... } ... </style> ... <div style="color: red; ... "><!-- /* +this 4th level */ -->CSS 規範上說: stylesheet 的來源有 user agent, author 及 user 等三種. user agent 就是我們用的 browser 指的是 browser 的預設值; author 是作者的意思, 指的是網頁的作者在網頁上所使用的 stylesheet; 而 user 就是我們, 指的是我們在 browser 中的個人用的 stylesheet 設定. 而套用的次序是:
user agent user normal author normal author important user important一來由於調整 stylesheet 的設定不容易, 二來由於各網站的網頁對於各種 HTML tag 的運用都不相同, 造成 user stylesheet 其實發揮不了什麼作用, 搞不好一設就破壞了原網頁的排版, 造成閱讀上的困難, 是故絕大多數人的 user stylesheet 都是空的. 因此上述的五項也就只剩下 1, 3, 4 三項了. 其中 auther important 指的是 author stylesheet 中設定值的後面附有 !important 的設定, 所以真正需要討論就是只有 author 部份.
網頁作者 (author) 可以運用的元素樣式 (style) 來源有以下幾種:
外部 style...