且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

< section>的区别是什么?和< div> ;?

更新时间:2022-12-08 18:08:26

< section> 表示内部的内容被分组(即与单个主题相关),并应该作为页面大纲中的条目出现。



类$ c $中的任何内容外, 并不表示任何意义 c>, lang title 属性。



no:使用< div> 不会定义HTML中的一段。




$ b $ h




$ b $ p> < section> 元素表示文档或应用程序的通用部分。在这方面,一节是内容的主题分组。应该标识每个部分,通常通过包括标题(h1-h6元素)作为< section> $ c $的子元素c>元素。



章节的例子可以是章节,标签对话框中的各种标签页或者论文的编号部分。一个网站的主页可以分成几个部分介绍,新闻和联系信息。



...



< section> 元素不是通用的容器元素。当仅仅为了样式目的或为了方便脚本而需要元素时,鼓励作者改为使用< div> 元素。一般的规则是,只有元素的内容在文档的大纲中明确列出时,< section> 元素才是合适的。


https://www.w3.org/TR/html/sections.html#the-section-element



< div>




< div> 元素根本没有特别的意义。它代表了它的孩子。它可以用于 lang title 属性来标记一组连续元素共有的语义。



注意:强烈建议作者查看< div> 元素作为最后一招的元素,因为当没有其他元素适合时。使用更合适的元素而不是< div> 元素可以更好地为读者提供可访问性,并且为作者提供更易于维护的功能。

https ://www.w3.org/TR/html/grouping-content.html#the-div-element


What is the difference between <section> and <div> in HTML? Aren't we defining sections in both cases?

<section> means that the content inside is grouped (i.e. relates to a single theme), and should appear as an entry in an outline of the page.

<div>, on the other hand, does not convey any meaning, aside from any found in its class, lang and title attributes.

So no: using a <div> does not define a section in HTML.

From the spec:

<section>

The <section> element represents a generic section of a document or application. A section, in this context, is a thematic grouping of content. Each section should be identified, typically by including a heading (h1-h6 element) as a child of the <section> element.

Examples of sections would be chapters, the various tabbed pages in a tabbed dialog box, or the numbered sections of a thesis. A Web site’s home page could be split into sections for an introduction, news items, and contact information.

...

The <section> element is not a generic container element. When an element is needed only for styling purposes or as a convenience for scripting, authors are encouraged to use the <div> element instead. A general rule is that the <section> element is appropriate only if the element’s contents would be listed explicitly in the document’s outline.

(https://www.w3.org/TR/html/sections.html#the-section-element)

<div>

The <div> element has no special meaning at all. It represents its children. It can be used with the class, lang, and title attributes to mark up semantics common to a group of consecutive elements.

Note: Authors are strongly encouraged to view the <div> element as an element of last resort, for when no other element is suitable. Use of more appropriate elements instead of the <div> element leads to better accessibility for readers and easier maintainability for authors.

(https://www.w3.org/TR/html/grouping-content.html#the-div-element)