2019-08-26
描述
CSS 变量包含在整个文档中可重复使用的特定值。
HTML
<p class="custom-variables">CSS is awesome!</p>
CSS
:root {
  /* Place variables within here to use the variables globally. */
}
.custom-variables {
  --some-color: #da7800;
  --some-keyword: italic;
  --some-size: 1.25em;
  --some-complex-value: 1px 1px 2px whitesmoke, 0 0 1em slategray, 0 0 0.2em slategray;
  color: var(--some-color);
  font-size: var(--some-size);
  font-style: var(--some-keyword);
  text-shadow: var(--some-complex-value);
}
Demo
说明
- 在 :rootCSS 伪类中可定义全局变量,他和文档中树的根结点元素相匹配。如果在块中进行定义,变量也可以在该选择器的作用域中使用
- 使用 --variable-name:声明一个变量
- 使用 var(--variable-name)函数可在整个文档中重复使用变量
浏览器支持
支持率:91.6%
支持情况:https://caniuse.com/#feat=css-variables
 
         ME!
                
                ME!
             链滴
                
                链滴
            
