有没有更好的方法在 XHTML 1.0 Transitional 中对 FAQ 进行语义编码? [英] Is there a better way to semantically code up an FAQ in XHTML 1.0 Transitional?

查看:23
本文介绍了有没有更好的方法在 XHTML 1.0 Transitional 中对 FAQ 进行语义编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 XHTML 1.0 的常见问题解答的以下代码段将无法在 W3C 验证器.

我将 Q&A 插入到定义列表中以维护问题 &从语义上回答关系.问题是,问题可以是多个段落.而

标签,至少在 XHTML 1.0 中,只允许内联元素.所以我不能在其中放置 <p> 标签而不在 W3C 验证器中抛出错误.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><头><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title>无标题文档</title><身体><dl><dt><p>这是一个很长的问题.</p><p>它有多个段落.</p></dt><dd><p>这就是答案</p></dd></dl></html>

使用 XHMTL 1.0 Transitional 是否有更好的语义编码方式?

作为参考,我可以在该主题上找到的最新类似线程是 语义结构常见问题解答的最佳方式是什么?.该线程很有用,但它没有涵盖问题中的多个段落.

解决方案

使用 dl 元素似乎并不合适.

XHTML 1.0 使用 HTML 4.01 中的元素定义,其中 dl element 被定义为一个定义列表".Q&As 列表可能不是定义列表(除非,可能要定义的术语只是用问题来表达,例如,foo 的定义是什么?").>

HTML5 重新定义了 dl 元素:它不再是一个定义列表,而是一个关联列表"或描述列表".将它用于问答可能是合适的,并且 dt 元素 现在还可以包含大部分流内容元素(包括 p).因此,如果您想使用 (X)HTML5,这可能是合适的.( 的示例dt 甚至显示了一个常见问题.)

可能的替代方案,取决于实际内容和上下文:

  • 只需使用 p 并依赖于文本语义,即?"明确表示这是一个问题.您还可以在它们前面加上问题:"和答案:"(例如,在 b 中).
  • 为每个问答使用标题 (h1-h6).由于它们都不可能包含 p 元素,因此您可能必须使用问题 1"之类的内容作为标题内容,并再次依赖文本.

The following code segment for an FAQ, which uses XHTML 1.0, will not validate successfully in the W3C validator.

I’m inserting the Q&A into a definition list in order to maintain the question & answer relationship semantically. The problem is, the questions can be multiple paragraphs. And the <dt> tag, at least in XHTML 1.0, only allows for inline elements. So I can’t put a <p> tag in there without throwing an error in the W3C validator.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<dl>
    <dt>
        <p>This is a very long question.</p>
        <p>It has multiple paragraphs.</p>
    </dt>

    <dd>
        <p>This is the answer</p>
    </dd>
</dl>
</body>
</html>

Is there a semantically better way of coding this using XHMTL 1.0 Transitional?

For reference, the latest similar thread I can find on the topic is this is What is the best way to semanticly structure a FAQ?. The thread was useful, however it does not cover multiple paragraphs in the question.

解决方案

Using the dl element doesn’t seem to be appropriate.

XHTML 1.0 uses the element definitions from HTML 4.01, where the dl element is defined to be a "definition list". A list of Q&As is probably not a definition list (unless, maybe, the term to be defined is just phrased as question, e.g., "What is the definition of foo?").

HTML5 re-defines the dl element: it’s no longer a definition list, but an "association list", or "description list". It might be appropriate to use it for Q&As, and the dt element can now also contain most of the flow content elements (which includes p). So this might be suitable if you want to use (X)HTML5. (The example for dt even shows a FAQ.)

Possible alternatives, depending on the actual content and context:

  • Just use p and rely on textual semantics, i.e., the "?" makes clear that it’s a question. You could also prefix them with "Question:" and "Answer:" (e.g., in b).
  • Use a heading (h1-h6) for each Q&A. As they neither may contain p elements, you might have to use something like "Question 1" as heading content, and rely on the text again.

这篇关于有没有更好的方法在 XHTML 1.0 Transitional 中对 FAQ 进行语义编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆