在幕后,HTML5 标签(文章、部分、旁白、页眉、页脚)是否像 div 一样实现?
我知道所有这些标签都有不同的语义含义,例如 article
代表一个独立的故事; section
用于页面的独立部分...
它们在很多方面都是良好且有用的标签。但是,它们只是语法糖吗?因为我没有看到他们之间有任何风格差异。当不应用任何 CSS 规则时,它们就像 div
一样。
希望一些webkit/gecko专家能在代码层面上澄清一下。
I understand all these tags have different semantic meanings, like article
is for a story that stand apart; section
is for self-contained part of the page...
They are good and useful tags, in many ways. But, are they just syntax sugar? Because I didn't see any style differences among them. When not applied by any CSS rules, they are just like div
s.
Hope some webkit/gecko experts can clarify it on the code level.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
大多数情况下是的。它们实际上并不是 div,而是块级元素(微妙但不同)。
http://diveintohtml5.info/semantics.html#new-elements
所以是的,目前它们只是为了缩短代码长度并创建更清晰的标记,但这就是块级元素的作用。如果从
标记中删除默认样式,它是不是就像
Mostly yes. They're not actually divs, but block level elements (subtle but different).
http://diveintohtml5.info/semantics.html#new-elements
So yes, for now they are just there for shortening your code length and creating cleaner markup, but that's what block level elements do. If you remove the default styling from a
<p>
tag isn't it just like a<div>
?每个浏览器都有自己的应用于页面内容的本机样式表。这就是我们通常使用 CSS 重置样式表的原因 - 标准化不同浏览器样式表之间的所有内容。样式和内容是两个完全独立的事物,看起来像与它是什么无关,因此您不应该根据您想要的方式标记页面出现。
有一天,浏览器向某些 HTML5 元素添加默认样式可能很常见,例如
上的一些填充,但这并不重要(实际上不太可能)。
一点也不。虽然看起来可能没有太大区别,但它允许屏幕阅读器或搜索引擎以更有意义的方式理解您的内容。
正如 Grillz 的回答提到的,所讨论的元素都是块级元素,因此在这方面 - 它们基本上呈现为 < code>div,但具有语义值,并不意味着用作通用容器元素。
Each browser has it's own native stylesheet that is applied to the page content. This is why we commonly use CSS reset stylesheets - to normalize everything between different browser stylesheets. Style and content are two completely separate things, what something looks like has no bearing on what it is, therefore you should not be marking up your page based on how you want it to appear.
Some day, it may be common for browsers to add default style to certain HTML5 elements, like some padding on
<section>
s, but it doesn't matter (and is actually unlikely).Not at all. While there may not seem to be much of a difference, it allows your content to be understood by, for example, screen readers or search engines, in a more meaningful way.
As Grillz's answer mentions, the elements in question are all block level elements, so in that respect - they are basically rendered like
div
s, but have semantic value and aren't meant to be used as generic container elements.