< section>的区别是什么?和< div> ;? [英] What is the difference between <section> and <div>?
问题描述
HTML中的< section>
和< div>
有什么区别?我们是不是在两种情况下都定义了部分?
< section>
表示内部的内容被分组(即与单个主题相关),并应该作为页面大纲中的条目出现。
<$ 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 itsclass
,lang
andtitle
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. Eachsection
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 theclass
,lang
, andtitle
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)
这篇关于< section>的区别是什么?和< div> ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!