Html 我可以在 DL/DT/DD 中​​放入任何东西吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6392513/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 09:10:04  来源:igfitidea点击:

Can I put anything inside DL/DT/DDs?

htmlhtml-lists

提问by Alex

can I use definition lists just like unordered/ordered lists?

我可以像使用无序列表/有序列表一样使用定义列表吗?

I mean insert DIVs any anything I want inside DT or DD?

我的意思是在 DT 或 DD 中插入任何我想要的 DIV?

<dl>
  <dt>
    ...
  </dt>
  <dd>
    ...
  </dd>
</dl>

Do any browsers, or search engines complain?

是否有任何浏览器或搜索引擎抱怨?

回答by Town

Updated answer based on comments:

根据评论更新答案:

This was originally answered in 2011 for HTML 4, but the answer is different for HTML5:

这最初是在 2011 年针对 HTML 4 回答的,但针对 HTML5 的回答有所不同:

dtFlow content, but with no header, footer, sectioning content, or heading content descendants. ddFlow content.

dt流内容,但没有页眉、页脚、分节内容或标题内容后代。 dd流内容。

Original answer:

原答案:

DTelements should contain inline content.
DDelements should contain block-level content.

DT元素应包含内联内容
DD元素应包含块级内容

Definition lists vary only slightly from other types of lists in that list items consist of two parts: a term and a description. The term is given by the DT element and is restricted to inline content. The description is given with a DD element that contains block-level content.

Source:W3C

定义列表与其他类型的列表略有不同,该列表项由两部分组成:术语和描述。该术语由 DT 元素给出,仅限于行内内容。描述是通过包含块级内容的 DD 元素给出的。

资料来源:W3C

This question is also an interesting read: Why use definition lists (DL,DD,DT) tags for HTML forms instead of tables?

这个问题也是一个有趣的阅读:为什么对 HTML 表单而不是表格使用定义列表(DL、DD、DT)标签?

回答by Arjan

Inside a DLyou can only put DTand DDtags. A DTtag is an inline tag, so you should not put block elements in it. A DDtag can contain basically anything you want, it's a flow content tag.

在 a 中,DL您只能放置DTDD标记。一个DT标签是一个内嵌标签,所以你不应该把块元素在里面。一个DD标签基本上可以包含任何你想要的,这是一个流动的内容标签。

回答by Smithee

As of December 2017 according to HTML 5.2 Specification, you can now add a single nested <div>tag inside a <dl>tag, I assume for styling purposes:

根据 HTML 5.2 规范,截至 2017 年 12 月,您现在可以在<div>标签内添加单个嵌套<dl>标签,我假设出于样式目的:

https://www.w3.org/TR/html52/grouping-content.html#the-dl-element

https://www.w3.org/TR/html52/grouping-content.html#the-dl-element

Content model:

Either: Zero or more groups each consisting of one or more dt elements followed by one or more dd elements, optionally intermixed with script-supporting elements.

Or: One or more div elements, optionally intermixed with script-supporting elements.

内容模型:

要么: 零个或多个组,每个组由一个或多个 dt 元素后跟一个或多个 dd 元素组成,可选地与支持脚本的元素混合。

或者:一个或多个 div 元素,可选择与支持脚本的元素混合。