gtxyzz

CSS var() 函数 自定义元素属性插入css样式中

gtxyzz web技术 2022-07-07 563浏览 0

CSS var() 函数 自定义元素属性插入css样式中

实例

首先定义一个名为 "--main-bg-color" 的自定义属性,然后使用 var() 函数在样式表中插入该自定义属性的值:

:root {
  --main-bg-color: coral; 
}
#div1 {
  background-color: var(--main-bg-color); 
}
#div2 {
  background-color: var(--main-bg-color);
}

定义和用法

var() 函数用于插入自定义属性的值,而不是另一个属性的值的任何部分。

CSS 语法

var(custom-property-name, value)


var() 函数

Shanghai is one of the four direct-administered municipalities of the People's Republic of China. Welcome to Shanghai!


Shanghai is one of the four direct-administered municipalities of the People's Republic of China. Welcome to Shanghai!


Shanghai is one of the four direct-administered municipalities of the People's Republic of China. Welcome to Shanghai!

继续浏览有关 css 的文章
发表评论