欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

CSSStyleDeclaration未找到属性?解决方案:cssText的妙用

最编程 2024-08-10 12:41:39
...

cssText 也是 style: CSSStyleDeclaration 的一个属性,是将 css 压缩成一行之后的结果

style = {
  width: "100px";
  height: "200px";
  cssText: "zoom: 50%;border:1px solid red"
};
  1. cssText 里可以有多个属性
  2. cssText 权重比 style.xx 高
    1. 即使将 style.xx 写在 cssText 后也是如此
    2. 可能是因为 css 解析的时候是最后解析 cssText 的,将它 Parse 成 Json 缀到后面的
  3. 为避免 cssText 值被覆盖,应使用 cssText+=…,而非 cssText=