简体   繁体   English

在引擎盖下,HTML5标签(文章,部分,旁边,页眉,页脚)是否像div一样实现?

[英]Under the hood, are HTML5 tags (article, section, aside, header, footer) implemented just like div?

I understand all these tags have different semantic meanings, like article is for a story that stand apart; 我理解所有这些标签都有不同的语义含义,就像article是一个独立的故事; section is for self-contained part of the page... section是针对页面的自包含部分...

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. 当没有被任何CSS规则应用时,它们就像div一样。

Hope some webkit/gecko experts can clarify it on the code level. 希望一些webkit / gecko专家能够在代码级别上澄清它。

Mostly yes. 大多数是的。 They're not actually divs, but block level elements (subtle but different). 它们实际上不是div,而是块级元素(微妙但不同)。

http://diveintohtml5.info/semantics.html#new-elements http://diveintohtml5.info/semantics.html#new-elements

There are several new elements defined in HTML5 which are block-level elements. HTML5中定义了几个新元素,它们是块级元素。 That is, they can contain other block-level elements, and HTML5-compliant browsers will style them as display:block by default. 也就是说,它们可以包含其他块级元素,并且符合HTML5的浏览器将它们设置为display:block默认情况下。

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> ? 如果从<p>标签中删除默认样式,是不是就像<div>

I didn't see any style differences among them. 我没有看到他们之间有任何风格差异。 When not applied by any CSS rules, they are just like divs. 如果没有任何CSS规则应用,它们就像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. 这就是我们通常使用CSS重置样式表的原因 - 规范化不同浏览器样式表之间的所有内容。 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). 有一天,浏览器可能会将默认样式添加到某些HTML5元素中,例如<section>的某些填充,但它无关紧要(实际上不太可能)。

Are they just syntax sugar? 它们只是语法糖吗?

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. 正如Grillz的回答所提到的,所讨论的元素都是块级元素,因此在这方面 - 它们基本上像div一样呈现,但具有语义价值,并不打算用作通用容器元素。

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

相关问题 使用HTML5标签有什么好处 <article> , <section> , <figure> , <header> , <footer> , <nav> ? - What is the benefit of using HTML5 tags like <article>, <section>, <figure>, <header>, <footer>, <nav>? HTML5有新的标签文章,部分和旁边。我什么时候应该使用div标签? - HTML5 has new tags article, section and aside. When should I use div tag? HTML 5是新标签header / nav / aside / section等容器,例如div吗? - HTML 5 are the new tags header/nav/aside/section etc containers like div? CodedUI GetChildren()不返回带有HEADER,SECTION,ARTICLE,NAV等HTML5标签的子级 - CodedUI GetChildren() doesn't return children with HTML5 tags like HEADER, SECTION, ARTICLE, NAV HTML5语义标签(文章,页脚,标题)的降级问题 - Degradation issues for HTML5 semantic tags (article, footer, header) 与div元素相比,HTML5部分,文章和aside元素令人困惑 - Confusion about HTML5 section, article and aside element compared to div element 如何使用 <section> 和 <article> HTML5中添加标签? - How to use <section> and <article> tags in HTML5? HTML5:页脚,页眉和文章 - HTML5: Sticky footer, header and article HTML5 <section> 在里面 <article> 和标题 - HTML5 <section>'s inside <article> and header HTML5结构 - <article> , <section> 和 <div> 用法 - HTML5 Structure - <article>, <section> and <div> usage
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM