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

标签 css html language-lawyer w3c

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

例如,Internet Explorer 11 及更早版本 (source) 不支持 HTML5 main 元素。当 main 被 IE 渲染时,涉及 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.

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

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

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

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

关于css - 无法识别的 HTML 元素的默认设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35689456/

相关文章:

c++ - 是否定义了静态初始化实现的顺序?

css - jQuery 选项卡需要移动

java - INPUT box-sizing border-box with 100% height and width inside TD issue in Chrome

javascript - 使用标签而不是 anchor 文本

javascript - HTML 按钮未链接到 JavaScript 函数

html - 中心堆栈图像和 span 标签 - bootstrap

c - 在将指针转换为 `void *` 之前是否需要转换为 `uintptr_t`,反之亦然?

css - Windows 手机上的 Html5

css - 为什么我不能让 HTML 视频标签顶部对齐?

c++ - 为无效迭代器定义了哪些操作?