HTML 5语义标签 [英] HTML 5 semantic tags

查看:95
本文介绍了HTML 5语义标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了有关W3C,WHATWG和MDN的一些语义元素,但是在某些方面我仍然不清楚.我还访问了这篇文章,在补充工具栏和Aside上有所不同!

I have read about some of the semantic elements on W3C, WHATWG, and MDN, but I still a little unclear on somethings. I also went to this article, on Sidebar and Aside are different!.

我有几个基本问​​题,或者确认我正在理解所读内容:

I have a few basic questions, or confirm that I am understanding what I have read:

  • aside元素不是边栏吗?

在HTML5中,我们可以使用语义和div标签吗?

In HTML5, can we use semantic and div tags?

当没有语义标记可使用时,HTML5中是否可以使用div标记(这可能与上面的问题相同)?

When there are no semantic tags to use, is a div tag acceptable in HTML5 (this may be the same question as above)?

语义main元素是否可以嵌入其他语义标签,例如tablesectionarticleaside,但不限于此?

Can the semantic main element have other semantic tags embedded within, such as table, section, article and aside, but not limited to?

推荐答案

请记住,语义标记只是使代码更易于阅读和标准化页面的一种方式.

Keep in mind that semantic tags are just a way to keep the code more human readable and to standardize pages.

这是因为在大多数用户之前,先定义divs,然后再定义class来描述其角色,例如navfooterheader等.

This is because before most users would define just divs and then a class describing its role like nav, footer, header, etc.

第一个问题;不,aside元素本身并不表示补充工具栏".它仅表示与主要内容相关的内容,但不属于页面主要主题.您可以使用它来包装侧边栏(其本身就是UI组件)的内容,但也可以将其用于其他用途.

For your first question; no, an aside element does not represent a "sidebar" per se. It just represents content that is related to the main content, but it's not part of the main topic of the page. You could use it to wrap the contents of a sidebar (which is in itself a UI component), but you can use it for other things as well.

来自 HTML5规范:

aside元素表示页面的一部分,该部分由与aside元素周围的内容切向相关的内容组成,可以认为与该内容是分开的.在印刷版式中,此类部分通常表示为侧边栏.

The aside element represents a section of a page that consists of content that is tangentially related to the content around the aside element, and which could be considered separate from that content. Such sections are often represented as sidebars in printed typography.

该元素可用于印刷效果,例如拉引号或 侧边栏,用于广告,导航元素组和其他 与页面的主要内容分开的内容.

The element can be used for typographical effects like pull quotes or sidebars, for advertising, for groups of nav elements, and for other content that is considered separate from the main content of the page.

第二个问题.

是的,在HTML5中,您可以随时使用divs或语义标记,但建议您尽可能使用语义;如果没有其他标记可用于定义文档的一部分,则使用div不会出现问题.您可以互换使用它们,最后,它们中的大多数(例如mainsectionfooter等)只是divs,具有不同的名称,以便于阅读.

Yes, in HTML5 you can use divs or semantic tags whenever you like, but it is encouraged that you use semantics whenever possible; if there's no other tag you can use to define part of the document, then use a div without problems. You can use them interchangeably, at the end, most of them like main, section, footer, etc. are just divs with a different name to make it easier to read.

这篇关于HTML 5语义标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆