CSS 自定义属性放置 :root vs body/html 标签
CSS custom properties placement :root vs body/html tags
在 :root
而不是 body
或 html
标签中定义全局 CSS 自定义属性有什么意义。这会导致不同的效果或性能问题吗?
嗯,一开始它可能很奇怪,但除了 specificity. :root
is actually html
itself with a higher specificity, so the main reason for putting variables in :root
element is because we are not only using them in CSS but we are using them in SVG and XML also. So we may call :root
global scope as its usage. You can also read more about their actual difference here。
它允许您定义各种变量并在需要时使用它们。 _root 代表 html 元素 - 你有没有为 hrml 标签附加样式?
性能 - 不会打扰...
在 :root
而不是 body
或 html
标签中定义全局 CSS 自定义属性有什么意义。这会导致不同的效果或性能问题吗?
嗯,一开始它可能很奇怪,但除了 specificity. :root
is actually html
itself with a higher specificity, so the main reason for putting variables in :root
element is because we are not only using them in CSS but we are using them in SVG and XML also. So we may call :root
global scope as its usage. You can also read more about their actual difference here。
它允许您定义各种变量并在需要时使用它们。 _root 代表 html 元素 - 你有没有为 hrml 标签附加样式? 性能 - 不会打扰...