似乎无法找到这么多的信息。
碎杂志似乎本质上说, html
和:root
都是一样的东西,但肯定必须有区别吗?
似乎无法找到这么多的信息。
碎杂志似乎本质上说, html
和:root
都是一样的东西,但肯定必须有区别吗?
From the W3C wiki:
The
:root
pseudo-class represents an element that is the root of the document. In HTML, this is always the HTML element.
CSS is a general purpose styling language that it can be used with other document types, not only with HTML, such as SVG.
From the specification (emphasis mine):
This specification defines Cascading Style Sheets, level 2 revision 1 (CSS 2.1). CSS 2.1 is a style sheet language that allows authors and users to attach style (e.g., fonts and spacing) to structured documents (e.g., HTML documents and XML applications).
它们之间的一个技术区别是:root
-是一个伪类具有比更高的特异性html
(类型选择)
:root { color: red } html { color: green; }
<div>hello world</div>
因此,在上述例子中, :root
选择覆盖html
选择器和文本显示为红色。
对于一个html
文件,当然根元素是<html>
标记。 但是你可以风格的CSS,现在你的SVG文档:root
伪类referd到svg
元素。
您可以使用CSS不仅HTML,但所有类似XML doucments,这就是为什么:root
,一般适用于根元素,无论文档类型(其中的情况下,然而在99%以上将是HTML)。