更合适,但我不知道是否可以在其中添加
如果您只需要一些有用的东西,那么制作搜索结果列表(就像在 Google 中一样)并不难。然而现在,我想利用 HTML5 语义的优势来完美地做到这一点。目标是定义标记搜索结果列表的事实上的方式,该列表可能被任何未来的搜索引擎使用。
对于每个点击,我想
我的第一个想法是这样的:
<ol>
<li>
<article>
<header>
<h1>
<a href="url-to-the-page.html">
The Title of the Page
</a>
</h1>
</header>
<p>A short summary of the page</p>
<footer>
<dl>
<dt>Categories</dt>
<dd>
<nav>
<ul>
<li><a href="first-category.html">First category</a></li>
<li><a href="second-category.html">Second category</a></li>
</ul>
</nav>
</dd>
<dt>File size</dt>
<dd>2 kB</dd>
<dt>Published</dt>
<dd>
<time datetime="2010-07-15T13:15:05-02:00" pubdate>Today</time>
</dd>
</dl>
</footer>
</article>
</li>
<li>
...
</li>
...
</ol>
我对 < 不是很满意
内的;article/>
。首先,搜索结果本身并不是一篇文章,而只是一篇非常简短的摘要。其次,我什至不确定您是否可以将文章放入列表中。也许 和
标签比
更合适,但我不知道是否可以在其中添加
欢迎所有建议和意见!我真的希望每一个细节都完美。
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
1) 我认为你应该坚持使用
article
元素,因为您只有一个单独文件的列表,所以我认为这是完全合适的。博客的首页也是如此,包含多个带有标题和大纲的帖子,每个帖子都位于一个单独的
article
元素中。此外,如果您打算引用文章中的几句话(而不是提供摘要),您甚至可以使用blockquote
元素,例如 论坛帖子示例,显示用户正在回复的原始帖子。2) 如果您想知道是否允许在
li
元素中包含article
元素,只需将其提供给验证器即可。正如您所看到的,这样做是被允许的。此外,正如工作草案< /a> 说:3) 我不会对这些类别使用
nav
元素,因为这些链接不是页面主导航的一部分:4) 不要使用
details
和/或summary
元素,因为它们用作 交互式元素,不适用于普通文档。更新:关于使用(无)有序列表来呈现搜索结果是否是个好主意:
由于搜索结果列表实际上是一个列表,我认为这是合适的元素;但是,在我看来,顺序很很重要(我希望最佳匹配结果位于列表的顶部),我认为您应该使用有序列表(
ol< /代码>) 改为:
使用 CSS,您可以简单地隐藏数字。
编辑:哎呀,我刚刚意识到你已经使用了
ol
(由于我的疲劳,我以为你使用了ul
)。我将保留我的“更新”不变;毕竟,它可能对某人有用。1) I think you should stick with the
article
element, asYou merely have a list of separate documents, so I think this is fully appropriate. The same is true for the front page of a blog, containing several posts with titles and outlines, each in a separate
article
element. Besides, if you intend to quote a few sentences of the articles (instead of providing summaries), you could even useblockquote
elements, like in the example of a forum post showing the original posts a user is replying to.2) If you're wondering if it's allowed to include
article
elements inside ali
element, just feed it to the validator. As you can see, it is permitted to do so. Moreover, as the Working Draft says:3) I wouldn't use
nav
elements for those categories, as those links are not part of the main navigation of the page:4) Do not use the
details
and/orsummary
elements, as those are used as part of interactive elements and are not intended for plain documents.UPDATE: Regarding if it's a good idea to use an (un)ordered list to present search results:
As a list of search results actually is a list, I think this is the appropriate element to use; however, as it seems to me that the order is important (I expect the best matching result to be on top of the list), I think that you should use an ordered list (
ol
) instead:Using CSS you can simply hide the numbers.
EDIT: Whoops, I just realized you already use an
ol
(due to my fatique, I thought you used anul
). I'll leave my ‘update’ as is; after all, it might be useful to someone.我会以这种方式标记它(不使用任何 RDFa/微数据词汇表或微格式;因此仅使用纯 HTML5 规范给出的内容):
start
attribute forol
如果搜索引擎使用分页,您应该给
ol
赋予start
属性,以便每个li
反映正确的排名位置。每个
li
的id
每个
li
都应该获得id
属性,以便您可以链接到它。该值应该是等级/位置。人们可能认为应该将
id
赋予article
,但我认为这是错误的:排名/顺序可能会随着时间而改变。您指的不是具体结果,而是结果位置。删除
header
如果它仅包含标题 (
h1
),则不需要。将
rel="external"
添加到链接每个搜索结果的链接都是一个外部链接(通向不同的网站),因此应该获取
rel
值外部
。删除
nav
类别链接不是
文章
范围内的导航。因此删除nav
。dd
中的每个类别您使用的
:相反,您应该在其自己的
dd
中列出每个类别并删除ul
:abbr< /code> 文件大小
“2 kB”中的单位应该用
abbr
标记:删除
pubdate
属性它不再出现在规范中。
其他可以做的事情,
hreflang
属性,lang
属性(如果它是)使用与搜索引擎摘要不同的语言blockquote
(带有cite
属性)而不是p
摘要本身,但使用元描述或页面中的片段。q
(带有cite
属性)I'd markup it up this way (without using any RDFa/microdata vocabularies or microformats; so only using what the plain HTML5 spec gives):
start
attribute forol
If the search engine uses pagination, you should give the
start
attribute to theol
, so that eachli
reflects the correct ranking position.id
for eachli
Each
li
should getid
atribute, so that you can link to it. The value should be the rank/position.One could think that the
id
should be given to thearticle
instead, but I think this would be wrong: the rank/order could change by time. You are not referring to a specific result but to a result position.Remove the
header
It is not needed if it contains only the heading (
h1
).Add
rel="external"
to the linkThe link to each search result is an external link (leading to a different website), so it should get the
rel
valueexternal
.Remove
nav
The category links are not navigation in scope of the
article
. So remove thenav
.Each category in a
dd
You used:
Instead, you should list each category in its own
dd
and remove theul
:abbr
for file sizeThe unit in "2 kB" should be marked-up with
abbr
:Remove
pubdate
attributeIt's not in the spec anymore.
Other things that could be done
hreflang
attribute to the link if the linked result has a different language than the search enginelang
attribute to the link description and the summary if it is in a different language than the search engineblockquote
(withcite
attribute) instead ofp
, if the search engine does not create a summary itself but uses the meta-description or a snippet from the page.q
(withcite
attribute) if the link description is exactly the title from the linked webpage追求“完美”的 HTML5 模板是徒劳的,因为规范本身远非完美,新“语义”元素的大多数规定用例充其量也很模糊。只要您的文档以逻辑方式构建,搜索引擎就不会有任何问题(大多数新标签不会产生丝毫影响)。事实上,严格遵循 HTML5 规范 - 例如,在每个新的分区元素中使用
标签 - 可能会降低您的网站的可访问性(对于屏幕阅读器、例如)。不要追求“完美”或接近,因为它不存在 - HTML5 对此还没有经过深思熟虑。只需集中精力保持标记的逻辑性和整洁性即可。
Aiming for a 'perfect' HTML5 template is futile because the spec itself is far from perfect, with most of the prescribed use-cases for the new 'semantic' elements obscure at best. As long as your document is structured in a logical fashion, you won't have any problems with search engines (most of the new tags don't have the slightest impact). Indeed, following the HTML5 spec to the letter - for example, using
<h1>
tags within each new sectioning element - may make your site less accessible (to screen readers, for example). Don't strive for 'perfect' or close-to, because it doesn't exist - HTML5 is not thought-out well enough for that. Just concentrate on keeping your markup logical and uncluttered.我发现 HTML5 的一个很好的资源是 HTML5Doctor。检查文章档案以了解新标签的实际实现。请注意,这不是一个完整的参考,但足以轻松入门:)
如 页脚所示元素页面,部分可以包含页脚:)
I found a good resource for HTML5 is HTML5Doctor. Check the article archive for practical implementations of the new tags. Not a complete reference mind you, but nice enough to ease into it :)
As shown by the Footer element page, sections can contain footers :)