[英]Does this implicit div closing contradict the HTML spec?
In the following HTML code, my browser appears to be implicitly closing the div tag, such that cell one appears blue, but cell two does not.在下面的 HTML 代码中,我的浏览器似乎隐式关闭了 div 标记,这样单元格 1 显示为蓝色,但单元格 2 没有。
<table>
<td><div style="background:blue">cell one</td>
<td>cell two</td>
</div>
</table>
Intuitively, this seems like sensible behaviour, but it appears to contradict the HTML spec.直觉上,这似乎是明智的行为,但它似乎与 HTML 规范相矛盾。
From 12.2.9.6 Unclosed formatting elements从12.2.9.6 未封闭的格式元素
nested formatting elements (such as b) get collected and continue to be applied even as the elements they are contained in are closed
嵌套的格式化元素(例如 b)被收集并继续应用,即使它们所包含的元素已关闭
From 4.4.15 The div element从4.4.15 开始的 div 元素
Neither tag is omissible
两个标签都不可省略
My reading of this is that the opening of a new td
tag shouldn't implicitly close the div
tag, and therefore the styling should continue throughout the table.我对此的理解是,打开一个新的
td
标签不应该隐式关闭div
标签,因此样式应该在整个表格中继续。
Is there something in the spec that I've missed that makes the browsers' behaviour consistent with the spec or is the browser going outside of the formal spec?规范中是否有我遗漏的内容使浏览器的行为与规范一致,或者浏览器是否超出了正式规范?
Tested with Chrome, Firefox, IE, Edge使用 Chrome、Firefox、IE、Edge 进行测试
No because:没有为什么:
div
is not a formatting element div
不是格式元素The following HTML elements are those that end up in the list of active formatting elements: a, b, big, code, em, font, i, nobr, s, small, strike, strong, tt, and u.
以下 HTML 元素是那些最终出现在活动格式元素列表中的元素:a、b、big、code、em、font、i、nobr、s、small、strike、strong、tt 和 u。
See 12.2.6.4.15 The "in cell" insertion mode which says:见12.2.6.4.15 “in cell”插入模式,它说:
Generate implied end tags.
生成隐含的结束标签。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.