Is it possible to use CSS Custom Properties in values for the content property?

后端 未结 1 488
暖寄归人
暖寄归人 2020-12-19 12:49

Example:

:root {
    --PrimaryThemeColor: #3acfb6; /* with or without quotes */
}

.ColorSwatch:after {
  content: var(--PrimaryThemeColor);
}
相关标签:
1条回答
  • 2020-12-19 13:02

    The value of the custom property has to be a string (either a string literal, an attr() expression, or in the case of content any combination of any number of said tokens) in order for the corresponding var() expression to work correctly anywhere that a string is expected.

    It is not possible to convert a non-string value to a string or between any two data types through the var() function, if that's what you're asking. The value is always parsed, stored and substituted as-is, and the value can comprise any number of any kind of token, so converting between data types would be... pretty difficult.

    0 讨论(0)
提交回复
热议问题