js_获取与设置css变量的值

通过js获取设置的css变量的值

  • 已经设置好的css的变量值

    • :root{
          --main-white:#fff;
      }
      .theme_light {
        --header-bg: var(--main-white);
      }
      
  • 通过js获取已经设置好的css变量值

    • console.log(
       getComputedStyle(document.querySelector('.theme_light')).getPropertyValue('--header-bg')
      ) // #fff
      

通过js设置css变量

  • 设置css变量

    • document.querySelector('.theme_light').style.setProperty('--main-grey', '#ccc')
      
    • <div id="mobileDefaultLayoutContainer" class="theme_light" style="height: 100vh; --main-grey: #ccc;"></div>
      
posted @   Syinho  阅读(691)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 【.NET】调用本地 Deepseek 模型
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
历史上的今天:
2020-04-01 nodejs_buffer.copy
2020-04-01 nodejs_buffer.concat
点击右上角即可分享
微信分享提示