无法识别的 HTML 个元素的默认设置

Default settings of unrecognized HTML elements

如果我在我的 HTML 中使用自定义或不受支持的元素,它们仍然可以设置样式并且浏览器将呈现它们。

例如,Internet Explorer 11 及更早版本 (source) 不支持 HTML5 main 元素。当 IE 渲染 main 时,涉及 marginoverflow 的 CSS 规则将被忽略。这意味着无法识别的元素的 display 值为 inline.

在哪里定义了无法识别的元素的初始设置?

(注意:我不是在询问使用自定义元素的优缺点。我只是想知道 CSS 默认情况下的作用。)

与其说是 无法识别的 元素,不如说是 所有 元素。请记住 CSS 支持 XML 以及 HTML。在XML中,所有元素都无法识别

在 CSS 2.1 规范中,section 6.1.1 说:

6.1.1 Specified values

User agents must first assign a specified value to each property based on the following mechanisms (in order of precedence):

  1. If the cascade results in a value, use it. Except that, if the value is 'inherit', the specified value is defined in “The 'inherit' value” below.

  2. Otherwise, if the property is inherited and the element is not the root of the document tree, use the computed value of the parent element.

  3. Otherwise use the property's initial value. The initial value of each property is indicated in the property's definition.

根据定义,无法识别的元素不会在用户代理样式中提及 sheet,并且由于我们讨论的是默认行为,因此不会在作者样式中提及 sheet 任何一个。所以 1 不适用。

显示属性在9.2.4 The 'display' property中定义。那里的规则说 Inherited: no,所以 2 不适用。

所以 3 适用。同样根据 9.2.4 的规则,我们有 Initial: inline,因此元素是内联的。

对于 HTML 块级元素,它们默认是块级元素,因为它们在用户代理的样式中如此列出 sheet。同样对于其他显示值,例如 tablelist-item