HTML 5 语义

发布于 2024-11-29 05:24:32 字数 775 浏览 0 评论 0原文

我已经阅读了一段时间有关 HTML 5 的正确语义的内容,但仍然不确定某些事情。

我的网站从数据库输出如下:

  • 标题(当前使用

  • 描述(当前使用

  • 图像(当前使用 <) img> 并且没有包装元素)
  • 打开/关闭(当前使用

  • 服务
    • 苹果酒(是/否)
    • 葡萄酒(是/否)
    • 草稿(是/否)

我对此感到非常困惑:

每个结果

现在是否应该在
元素,因此页面将在
内输出 10 个结果,或者使用 1 在 html5 语义上正确
包含结果,因为它是结果
并且每个结果都保存在
中; ???

谢谢

I've been reading for a while now about the correct semantics of HTML 5 and am not sure about some things still.

My website outputs from the database like so:

  • Title (currently using <h2>)
  • Descrption (currently using <p>)
  • Image (currently using <img> and no wrapper element)
  • Open/Close (currently using <p>)
  • Services
    • cider (yes/no)
    • wine (yes/no)
    • draft (yes/no)

I am very confused with this:

should each result <div> now be within a <section> element, so a page would output 10 results all within a <section>, or would it be html5 semantically correct using 1 <section> to contain the results as it is a results <section> and each result is held within a <div id="unique_number"> ???

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千纸鹤带着心事 2024-12-06 05:24:32

部分是内容的主题分组,通常带有标题。
在您的情况下,我会为每个结果使用一个部分。

示例:

<section>
 <header><h1>Trollinger</h1></header>
  <p>Red, Delicious</p>
  <img/>
 <p>open</p>
 <ul>
  <li>cider</li>
  <li>wine</li>
  <li>draft</li>
 </ul>
</section>

参考: http://dev.w3.org/html5 /spec/Overview.html#the-section-element

A section is a thematic grouping of content, typically with a heading.
I would use a section foreach result in your case.

Example:

<section>
 <header><h1>Trollinger</h1></header>
  <p>Red, Delicious</p>
  <img/>
 <p>open</p>
 <ul>
  <li>cider</li>
  <li>wine</li>
  <li>draft</li>
 </ul>
</section>

Reference: http://dev.w3.org/html5/spec/Overview.html#the-section-element

三五鸿雁 2024-12-06 05:24:32

网页的标题应设置在 Title (位于 中)以及页面上(在body)和

。这对语义和 SEO 都很友好。

如果“描述”是独立的,则可以是 如果它是其他文本的一部分,则段落很好,但通常段落不会单独存在,因此请使用如果是这样的话。
图片:这要看情况。如果此图像纯粹用于样式(可能是背景中的漩涡或渐变),则应将其设置为 CSS 中元素的背景图像。如果它是实际内容(如徽标、照片),则使用 标记。
我猜“打开”和“关闭”是交互元素、链接或按钮。如果是这样,请使用

The title of a web page should be set in the <title>Title</title> (located in <head>) as well as on the page (in the body) with an <h1>. This is both semantic and SEO friendly.

The "description", if it stands alone, could be a <span>. If it's part of some other text, a paragraph is good, but generally paragraphs don't stand alone, so use a span if that's the case.
Image: it depends. If this image is purely for styling - perhaps a swirl in the backround or a gradient - it should be set as the background-image of an element in CSS. If it's actual content (like a logo, photo), then use the <img> tag.
I'm going to guess "Open" and "Close" are interactive elements, links, or buttons. If so, use a <button> or an anchor: <a>, not a paragraph. If these are headings, use one of the heading tags. Since you've used <h1>, then use <h2> (unless it's not a very important heading)

As to your "Results", according to the spec,

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.

Additionally,

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.

So in your case, a <div> for search results is probably fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文