logo

该视频仅会员有权观看

立即开通课程「Web前端页面基础」权限。

¥
199
/ 年

CSS 变量(Variables)

  • In CSS, you can define custom variables to set values.
  • These variable names start with two hyphens, for example, --primary-color.
  • The variable can then be used in stylesheets by referring to its name.
  • When the variable value is changed, all styles using that variable will update accordingly.
  • Variables can be defined within a specific element and used by all items nested within.
  • To use a variable in CSS, the var() function is employed.
  • As an example, setting the variable --primary-color to blue allows it to be used as a value for text color using color: var(--primary-color); for an h1 selector.
  • This results in elements, like a page title, displaying in the color blue as defined by the variable.