作者:黑白 | 来源:互联网 | 2023-07-14 12:04
ImlearningaboutHTML5,andhonestlyIcantsayImreallyimpressed.Semanticsareniceandall,
I'm learning about HTML5, and honestly I can't say I'm really impressed. Semantics are nice and all, but I think that they introduced new elements with a very thin line between them, and a even thinner line between them and the old divs.
我正在学习HTML5,说实话,我不能说我真的很感动。语义很好,但是我认为它们引入了新元素,它们之间有一条很细的线,它们和旧的div之间的线条更细。
Everything is very clear if you do a generic purpose site, like a blogging engine, news publishing portal, and similar, but web apps... I'm having a lot of dilemmas about new html elements.
如果您使用通用目的网站,如博客引擎,新闻发布门户网站以及类似网站应用程序,一切都非常清楚......我对新的html元素存在很多困境。
Here is my situation. I'm developing an ordering system. On the sellers interface I have 3 columns (inline), which represent the status of the order. When the status is changed element is moved from one column into another (background ajax, and js manipulation).
这是我的情况。我正在开发一个订购系统。在卖家界面上,我有3列(内联),表示订单的状态。当状态改变时,元素从一列移动到另一列(背景ajax和js操作)。
In Html4 I would use 3 divs and put a heading with a title on top of each one. Elements inside the columns would also be divs.
在Html4中,我会使用3个div并在每个顶部放置一个带标题的标题。列内的元素也是div。
But what about HTML5? I have been looking at the section element, but I'm not really sure how to use it. Here are the options:
但是HTML5怎么样?我一直在看截面元素,但我不确定如何使用它。以下是选项:
- Put everything inside one section - I don't think that is the way to go
将所有内容放在一个部分中 - 我不认为这是要走的路
- Put a section around each of the column divs, and heading inside the section
在每个列div周围放置一个部分,并在该部分内部标题
- Replace the divs with sections
用部分替换div
- Put sections inside column divs
将部分放在列div中
So, which way to go?
那么,走哪条路?
EDIT: first of all thanks everyone for your quick replies. In the end I'll probably go with Ian Devlins suggestion, and put each column as section. Anyway, just to point out my dissatisfaction with html5, multiple permitted options aren't always a good thing. I'm afraid what will the html5 web look like in a few years, when we can't fully agree on a simple question like this.
编辑:首先感谢大家的快速回复。最后,我可能会考虑Ian Devlins的建议,并将每一栏作为部分。无论如何,只是为了指出我对html5的不满,多个允许的选项并不总是一件好事。我担心几年后html5网络会是什么样子,当我们无法完全同意这样一个简单的问题时。
EDIT2: one more thing. I'll ask it here so I don't have to open another question. In addition to these 3 columns I have another div which contains order details, when any of the orders are selected. Should it be an article since its self-contained content, or to use an aside tag?
EDIT2:还有一件事。我会在这里问一下,所以我不必打开另一个问题。除了这3列之外,我还有另一个包含订单详情的div,当选择任何订单时。它应该是一篇文章,因为它是自包含的内容,还是使用旁边的标签?
3 个解决方案
3
To quote the w3.org spec:
引用w3.org规范:
The section element represents a generic section of a document or application. A section, in this context, is a thematic grouping of content, typically with a heading.
section元素表示文档或应用程序的通用部分。在此上下文中,部分是内容的主题分组,通常带有标题。
And another quote from the w3.org people:
还有来自w3.org人员的另一句话:
The section element is not a generic container element. When an element is needed 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.
section元素不是通用容器元素。当为了样式目的而需要一个元素或为脚本编写提供便利时,鼓励作者使用div元素。一般规则是,只有元素的内容在文档的大纲中明确列出时,section元素才是合适的。
Given the definition for section
by w3 we can conclude that your example would be a good use of section because:
根据w3节的定义,我们可以得出结论,你的例子可以很好地利用节,因为:
- The elements have a header
元素有一个标题
- It is a thematic grouping of content
它是内容的主题分组
- It is a part of the document outline.
它是文件大纲的一部分。
EDIT: To expand upon your comment below, the new HTML5 elements are NOT supposed to replace the old HTML4 elements. For example, going through a page and replacing all the div
elements with section
elements would be flat out wrong. The section
element was, in my opinion, intended to make it easier for machines to parse certain pages (think: feedburners) by giving a more semantic structure to a page. After all, what's easier to parse, a page with 30 div
elements, or a page with 10 div
5 header
5 section
5 article
and 5 footer
elements?
编辑:为了扩展您的评论,新的HTML5元素不应该取代旧的HTML4元素。例如,浏览一个页面并用section元素替换所有div元素将是错误的。在我看来,section元素旨在通过为页面提供更多语义结构,使机器更容易解析某些页面(想想:feedburners)。毕竟,什么更容易解析,一个页面有30个div元素,或一个页面有10 div 5标题5第5节文章和5个页脚元素?