当 Javascript 修改 CSS 时,CSS 特异性是什么?
如:
document.getElementById("demo").style.color = "red";
它被认为是内联样式吗?
最佳答案
CSS specificity when Javascript modifies CSS?
与通过编辑原始源代码而不是使用 JS 来修改 CSS 完全相同。
document.getElementById("demo").style.color = "red";
在这种情况下,您正在修改直接附加到元素的样式。
<div id="demo" style="color: red">
所以最大的特异性。 ( count 1 if the declaration is from is a 'style' attribute rather than a rule with a selector )
如果你曾经使用过 JS 到 modify a ruleset ,那么特异性就会不同。
关于javascript - Javascript 修改 CSS 时的 CSS 特异性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54654672/