CSS 函数 var() 的用法
cssweb developmentfront end technology更新于 2025/7/4 22:04:17
CSS 中的 var() 函数用于向网页添加自定义属性值。设置属性的自定义名称并设置其值。
示例
您可以尝试运行以下代码来实现 var() 函数
<!DOCTYPE html>
<html>
<head>
<style>
:root {
--my-bg-color: blue;
--my-color: white;
}
#demo {
background-color: var(--my-bg-color);
color: var(--my-color);
}
</style>
</head>
<body>
<h1>Heading One</h1>
<div id = "demo">
This is demo text. This is demo text. This is demo text.
This is demo text. This is demo text. This is demo text.
This is demo text. This is demo text. This is demo text.
</div>
<br>
</body>
</html>
相关文章
有用资源
css 参考教程 - 该教程包含有关 css 的更多信息:https://www.cainiaomax.com/css/

