虽然放在 DOM 分类里面,但是 CSS OM 并不属于 DOM,而是并行的。仅为方便查找。
document.styleSheets
<style title="hello">
a {
color: red;
}
</style>
<link rel="stylesheet" title="x" href="data:text/css,p%7Bcolor: blue%7D">
Rules
- document.styleSheets[0].cssRules
- document.styleSheets[0].insertRule("p{color: pink}", 0)
- document.styleSheets[0].removeRule(0)
Rule
- CSSStyleRule
- selectorText String
- style k-v结构
- CSSCharsetRule
- CSSImportRule
- CSSMedisRule
- CSSFontFaceRule
- CSSPageRUle
- CSSNamespaceRule
- CSSKeyframesRule
- CSSKeyframeRule
- CSSSupportsRule
- ...
getComputedStyle
- window.getComputedStyle(element, pseudoElement)
- element 想要获取的元素
- pseudoElement 可选 伪元素