Can I put anything inside DL/DT/DDs?

后端 未结 3 742
余生分开走
余生分开走 2020-12-28 17:02

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

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

...
相关标签:
3条回答
  • 2020-12-28 17:21

    Updated answer based on comments:

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

    dt Flow content, but with no header, footer, sectioning content, or heading content descendants. dd Flow content.

    • dt element reference on W3C
    • dd element reference on W3C

    Original answer:

    DT elements should contain inline content.
    DD elements should contain block-level content.

    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

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

    0 讨论(0)
  • 2020-12-28 17:25

    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:

    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.

    0 讨论(0)
  • 2020-12-28 17:48

    Inside a DL you can only put DT and DD tags. A DT tag is an inline tag, so you should not put block elements in it. A DD tag can contain basically anything you want, it's a flow content tag.

    0 讨论(0)
提交回复
热议问题