gpt4 book ai didi

javascript - Javascript 修改 CSS 时的 CSS 特异性?

转载 作者:行者123 更新时间:2023-12-02 06:27:21 24 4
gpt4 key购买 nike

当 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com