[CSS3] Create Dynamic Styles with CSS Variables
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');
[CSS3] Create Dynamic Styles with CSS Variables的更多相关文章
- Create Dynamic Modal Dialog Form in AdminLTE Bootstrap template
原文地址 Create modal dialog form in jquery using bootstrap framework, slightly different from the usual ...
- CSS Variables
CSS原生变量(CSS自定义属性) 示例地址:https://github.com/ccyinghua/Css-Variables 一.css原生变量的基础用法 变量声明使用两根连词线"-- ...
- [MST] Create Dynamic Types and use Type Composition to Extract Common Functionality
Since MST offers a runtime type system, it can create and compose types on the fly, making it possib ...
- CSS Variables:css自定义属性的使用
CSS Variables,一个并不是那么新的东西,但对css来说绝对是一场革命.之前使用变量的时候,需要借助sass.less等预处理工具来实现,现在我们可以直接使用css来声明变量. 一.兼容性 ...
- CSS3基础——笔记+实战案例(CSS基本用法、CSS层叠性、CSS继承性)
CSS3基础——笔记 CSS是Cascading Style Sheet的缩写,翻译为"层叠样式表" 或 "级联样式表".CSS定义如何显示HTML的标签央视, ...
- css variables & CSS 变量
css variables & CSS 变量 https://gist.github.com/xgqfrms-GitHub/5d022a13292c615d2730e84d909e1aba c ...
- [CSS3] Create a fixed-fluid-fixed layout using CSS calc()
CSS calc() allows you to mix and match units to get real-time calculations. It's useful when you nee ...
- css3复杂选择器+内容生成+Css Hack
1.复杂选择器2.内容生成3.多列4.CSS Hack(浏览器兼容性)=======================================1.复杂选择器 1.兄弟选择器 1.特点: 1.通过 ...
- CSS3条件判断——@supports/window.CSS.supports()(转)
CSS3条件判断,听起来"不明觉厉",如果你对CSS稍为熟悉一点的话,你会发现CSS中的"@media"就是条件判断之一.是的,在CSS3的条件判断规范文档中包 ...
随机推荐
- 《SAS编程与数据挖掘商业案例》学习笔记之十五
继续<SAS编程与数据挖掘商业案例>读书笔记,本次重点:输出控制 主要内容包含:log窗体输出控制.output窗体输出控制.ods输出控制 1.log窗体输出控制 将日志输出到外部文件 ...
- Hdu oj 1017 A Mathematical Curiosity
题目:pid=1017">点击打开链接 #include<stdio.h> int main() { int t; scanf("%d",&t) ...
- python 学习笔记 12 -- 写一个脚本获取城市天气信息
近期在玩树莓派,前面写过一篇在树莓派上使用1602液晶显示屏,那么可以显示后最重要的就是显示什么的问题了. 最easy想到的就是显示时间啊,CPU利用率啊.IP地址之类的.那么我认为呢,假设可以显示当 ...
- HTML5 格式化方式以及应用
<b>加粗字体 <big>定义大号字体 <em>定义着重文字 <i>定义斜体字 <small>定义小号字体 <strong>定义 ...
- 王立平--poser
Poser是Metacreations公司推出的一款lemmaId=234814&ss_c=ssc.citiao.link" style="color:rgb(51,102 ...
- angularjs1-8,cacheFactory,sce
<!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...
- How do I UPDATE from a SELECT in SQL Server?
方法1 https://stackoverflow.com/questions/2334712/how-do-i-update-from-a-select-in-sql-server UPDATE T ...
- 【IOI 2011】Race
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2599 [算法] 点分治 [代码] #include<bits/stdc++.h ...
- 最小生成树基础 (Kruskal)
最小生成树 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
- Python笔记(五)
# -*- coding:utf-8 -*- # 函数 # python中定义函数的规则如下:以def开头,接函数名称和(),传入的参数和变量放在圆括号中间,函数以:起始,并且缩进,return选择性 ...