“嵌套”有正式的定义吗?
在 HTML 中,嵌套到底意味着什么?是否有定义该术语的规范?
例如,一些消息来源指出,仅仅将任何元素放在另一个元素中就是嵌套:
<div>Thee is a span <span>nested</span> in this div</div>
其他消息来源说它们必须是同一类型的元素:
<span>There is a span <span>nested</span> in another span</span>
还有其他消息来源表明,仅当元素是唯一的直接子元素时才嵌套:
<span><span>nested</span></span>
是否有正式的定义,还是“嵌套”更像是一个随意的术语?与HTML的定义或规范有关吗?
In HTML, what does nesting mean exactly? Is there a specification which defines the term?
For example, some sources state that merely placing any element in another is nesting:
<div>Thee is a span <span>nested</span> in this div</div>
Other sources say that they must be elements of the same type:
<span>There is a span <span>nested</span> in another span</span>
Still other sources suggest that it is nested only if the elements is the only immediate child:
<span><span>nested</span></span>
Is there a formal definition, or is "nesting" more of a casual term? Is it related to the definition of HTML or the specifications?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
HTML 元素可能的嵌套可以从规范中得出。
HTML 4(和 XHTML 1.0)中允许的元素嵌套这些版本的演示基于:
(无法找到更完整的更新内容。)
嵌套就是将元素置于其他元素内部的树状结构。例如,请参阅嵌套 HTML 标签、嵌套,或 嵌套表(更直观的示例)。
不限制仅使用相同类型的标签(例如仅将嵌套视为将
div
放置在另一个div
中)。据我所知,这是一个非常通用的术语。The possible nesting of HTML elements can be derived from the specifications.
Allowed nesting of elements in HTML 4 (and XHTML 1.0) has a presentation for those versions based on:
(Can't find something more recent that is as complete.)
Nesting is simply the way you put elements inside others, in a tree-like structure. See for instance Nesting HTML tags, Nesting, or Nesting Tables (more visual example).
There is no restriction to only the same type of tag (like only considering nesting as placing
div
in anotherdiv
). It's a very generic term as far as I know.这是一个随意且上下文相关的术语。
一般来说,“嵌套 foos”的意思是“拥有一个 foo ,它是另一个 foo 的(不一定是直接)后代”。在不是嵌套特定事物的情况下,它通常仅意味着“在内部但在任何深度”
It is a casual and context sensitive term.
Generally, "Nested foos" means "Having a foo that is a (not necessarily direct) descendent of another foo". In a context where it isn't one specific thing being nested, it usually just means "inside but at any depth"