简体   繁体   English

为什么在块级和内联元素之间HTML在功能上存在差异?

[英]Why is there a functional difference in HTML between block level and inline elements?

Note: I am NOT talking about the display - I understand why they have different defaults. 注意:我不是在谈论显示器-我理解为什么它们有不同的默认值。 I'm talking about the functional differences between blocks and inline elements, esp. 我说的是块与内联元素之间的功能差异,尤其是。 in regards to things like nesting 关于诸如嵌套之类的东西

I've been told time and again that HTML is about describing content, what things do and what things are, not what they look like (beyond default stylistic elements associated with tags, that can be changed). 一次又一次地告诉我,HTML是关于描述内容,做什么,什么是事物,而不是它们的外观(与标记相关联的默认样式元素,可以更改)。

As such, it seems like the division between "block"-level tags and "inline"-level tags (not the display of those tags, but the inherent difference in those tags), something that trips up and complicated a great many neophyte and even more experience page designers, is arbitrary and... seemingly against principle, if you would. 这样,似乎是“块”级标签和“内联”级标签之间的划分(不是这些标签的显示,而是那些标签的固有差异),这使许多初生植物和复杂化了。甚至更多经验丰富的页面设计者,都是随心所欲的……似乎违背原则。 This sort of behaviour seems like something that should by controlled stylistically, not exist as a built-in element of a block. 这种行为似乎应该通过样式控制,而不是作为块的内置元素存在。 And in some ways, it IS controlled stylistically - we all know there is CSS that can make a span look like a div, and vice-versa. 在某些方面,它是由样式控制的-我们都知道有CSS可以使span看起来像div,反之亦然。

So what is the point of having the functional distinction between blocks and inlines? 那么,在块和内联之间进行功能区分又有什么意义呢? Why aren't they just like any other nested element? 为什么它们不像其他任何嵌套元素一样? Why isn't everything a "block" with "inline" elements simply set to "display: inline"? 为什么不是所有的带有“ inline”元素的“ block”都简单地设置为“ display:inline”? Is it just for, say, backwards compatibility, or is there a benefit to this seemingly arbitrary division that I'm just not seeing? 仅仅是为了向后兼容,还是这种我似乎没有看到的看似任意的划分有好处?

Note, this might be better as a community wiki question, since it's unlikely to have a single clear answer, but I'm not exactly sure on the details. 请注意,作为社区Wiki问题,这可能会更好,因为它不可能有一个明确的答案,但我不确定具体细节。

As an example, from what I understand, the following would be invalid html: 举例来说,据我了解,以下内容将是无效的html:

<label style="display:block">
 <h4>Name</h4>
 <span class='sub'>Whether legal, pseudonymous, or made up</span>
 <input id="name"></input>
</label>

Why? 为什么?

Why isn't everything a "block" with "inline" elements simply set to "display: inline"? 为什么不是所有的带有“ inline”元素的“ block”都简单地设置为“ display:inline”?

Well, it almost kind of is; 好吧,几乎是这样; just the inverse. 恰好相反。 Rather, everything is "inline" with "block" elements set to "display: block". 相反,所有内容都是“内联”,“块”元素设置为“显示:块”。

But that would be really annoying, if for every page you create, you need to tell it that div tags should be treated as block elements. 但这确实很烦人,如果对于您创建的每个页面,您都需要告诉它div标签应被视为块元素。 So for that reason, default styles are assumed, best illustrated at http://www.w3.org/TR/CSS2/sample.html 因此,出于这个原因,假定使用默认样式,最好在http://www.w3.org/TR/CSS2/sample.html上进行说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM