HTML <time>
元素表示24小时制的时间或公历中的精确日期(带有可选的时间和时区信息)。
例如:
<q>All is quiet on <time datetime="2018-01-01 00:00">New Year's Day</time></q>
考虑到这一点,<time>
似乎是提供文章发布日期和时间的明显标记:
<article itemscope itemtype="http://schema.org/Article">
<h2>Article Heading Here</h2>
<time datetime="2017-10-30" itemprop="datePublished">October 30th, 2017</time>
<p>Article Here</p>
</article>
通常情况下,文章会在发布日期和时间的同时提供报告位置。
但是,明确的地理位置似乎是<time>
的不恰当内容。
那么......如何最好地标记信息:
哈德斯菲尔德•2017年10月30日
到目前为止,我最喜欢的方法是使用通过CSS data-*
伪元素显示的HTML5 ::before
元素:
工作示例:
time::before {
content: attr(data-location) '\00a0\00a0\2022\00a0\00a0';
}
<time datetime="2017-10-30" itemprop="datePublished" data-location="Huddersfield">October 30th, 2017</time>
但是有更多的语义方法(使用schema.org微数据等)吗?
答案 0 :(得分:2)
由于dateline通常用于新闻文章,因此Schema.org仅为dateline
(Article
的子类型)定义NewsArticle
属性:
日期线是新闻文章中包含的一段简短文字,用于描述故事的编写地点和时间,尽管日期经常被省略。有时只提供地名。
它需要一个文本值。
日期线由地名和日期组成(假设发布日期为#34;故事编写或归档时为#34;)
<p itemprop="dateline">
Huddersfield • <time datetime="2017-10-30" itemprop="datePublished">October 30th, 2017</time>
</p>
日期行仅包含地名:
<p>
<span itemprop="dateline">Huddersfield</span> • <time datetime="2017-10-30" itemprop="datePublished">October 30th, 2017</time>
</p>