嵌套时间标签在 HTML5 中是否有效(在表达时间 period/duration 中)?
Are nested time tags valid in HTML5 (in expressing time period/duration)?
我试图用 <time>
标签来表达一个时间段,我想到了使用这个:
<time datetime="P4Y"><time>2000</time>-<time>2004</time></time>
这是否有效且语义正确?如果不是,是否有任何 better/simpler 方式来表达类似的东西?
这来自 W3C
The time element represents its contents, along with a
machine-readable form of those contents in the datetime attribute. The
kind of content is limited to various kinds of dates, times, time-zone
offsets, and durations, as described below.
The datetime attribute may be present. If present, its value must be a
representation of the element's contents in a machine-readable format.
A time element that does not have a datetime content attribute must
not have any element descendants.
这是参考
http://www.w3.org/TR/html5/text-level-semantics.html#the-time-element
WHATWG and W3C specs say the same thing: that this does, at least, meet the content model (which is probably what you mean by "valid", insofar as a conformance checker would accept it) of the time
element (though the (pretty much unmaintained) W3C fork contains a contradiction in its definition, whatwg/html#426).
简而言之:time
元素可以包含“Phrasing Content" if it has a datetime
attribute, and otherwise it can contain only "Text”; time
元素本身就是短语内容。上面的内容绝对是这种情况。
至于较长的问题是否在语义上正确(以及是否符合,因为语义正确性是 HTML 文档的一致性要求),必须考虑以下几点:
The time element represents its contents, along with a machine-readable form of those contents in the datetime attribute.
现在,这里的问题是 <time>2000</time>-<time>2004</time>
是否与 P4Y
具有相同的含义(即,它的内容和机器可读的日期时间属性是否仅在形式上有所不同):我会说这里很明确,这里有两种不同的语义。在内容中,您代表的是从 2000 年到 2004 年的特定时间间隔;在属性中,您代表的是一般的四年期限。这两个不相同,因此外部 time
元素在语义上是不可接受的。
我试图用 <time>
标签来表达一个时间段,我想到了使用这个:
<time datetime="P4Y"><time>2000</time>-<time>2004</time></time>
这是否有效且语义正确?如果不是,是否有任何 better/simpler 方式来表达类似的东西?
这来自 W3C
The time element represents its contents, along with a machine-readable form of those contents in the datetime attribute. The kind of content is limited to various kinds of dates, times, time-zone offsets, and durations, as described below.
The datetime attribute may be present. If present, its value must be a representation of the element's contents in a machine-readable format.
A time element that does not have a datetime content attribute must not have any element descendants.
这是参考
http://www.w3.org/TR/html5/text-level-semantics.html#the-time-element
WHATWG and W3C specs say the same thing: that this does, at least, meet the content model (which is probably what you mean by "valid", insofar as a conformance checker would accept it) of the time
element (though the (pretty much unmaintained) W3C fork contains a contradiction in its definition, whatwg/html#426).
简而言之:time
元素可以包含“Phrasing Content" if it has a datetime
attribute, and otherwise it can contain only "Text”; time
元素本身就是短语内容。上面的内容绝对是这种情况。
至于较长的问题是否在语义上正确(以及是否符合,因为语义正确性是 HTML 文档的一致性要求),必须考虑以下几点:
The time element represents its contents, along with a machine-readable form of those contents in the datetime attribute.
现在,这里的问题是 <time>2000</time>-<time>2004</time>
是否与 P4Y
具有相同的含义(即,它的内容和机器可读的日期时间属性是否仅在形式上有所不同):我会说这里很明确,这里有两种不同的语义。在内容中,您代表的是从 2000 年到 2004 年的特定时间间隔;在属性中,您代表的是一般的四年期限。这两个不相同,因此外部 time
元素在语义上是不可接受的。