In this lesson we are going to use CSS variables to keep our application's colors consistent. This includes defining the variables inside our the pseudo class :root and using the var function within our classes.

We finish up the lesson using JavaScript to log and modify our defined CSS variables.

Define a css variable:

:root {
--main: red; /*Define a css variable*/
} .title {
color: var(--main, white); /*Use main color as default, if not defined, then fallback to white color*/
}

Access css variable by Javascript:

const title = document.getElementById('.title');

console.log(getComputedStyle(title).getPropertyValue('--mian')) // red

Set dynamicly value of css variable from Javascript:

document.documentElement.style.setProperty('--main', 'green');

最新文章

  1. Oracle 中count(1) 和count(*) 的区别
  2. 【QT】C++ GUI Qt4 学习笔记3
  3. CSS 知识点
  4. Java解析XML三种常用方法
  5. svn中的图标解释
  6. 1 . Robberies (hdu 2955)
  7. 拖尾渲染器 Trail Renderer
  8. ios多视图开发中:xib与UIViewController的关联
  9. python 关于列表的增删改查及个别的命令
  10. IDEA- idea代码调试debug
  11. sql sever基本语法总结
  12. springMVC源码分析--AbstractHandlerMethodMapping注册url和HandlerMethod对应关系(十一)
  13. 3步永久性激活pycharm 亲测有效
  14. DAY16、模块和包
  15. java中使用JDBC的preparedStatement批处理数据的添加
  16. JAVA 中BIO,NIO,AIO的理解 (转)
  17. 解决远程连接mysql很慢的方法(网络正常)
  18. Redis 使用命令行的方式 获取 hash type key 的value值
  19. 基于socket构造c/s 架构软件
  20. windows中的常用Dos命令

热门文章

  1. iOS多线程与网络开发之解析json数据
  2. 彻底禁用resource manager
  3. MongoDB初探系列之四:MongoDB与Java共舞
  4. Spark SQL Catalyst源代码分析之Analyzer
  5. 数组进行多少次OP操作,才干有序
  6. Sort和UnSort的小技巧
  7. Vmware 安装samba
  8. [转]Linux+XAMPP+eolinker开源版v3.2.4
  9. FMDB条件更新
  10. 使用log4net记录日志到数据库(含自定义属性)