Proper way to make HTML nested list?

前端 未结 7 1280
执念已碎
执念已碎 2020-11-22 04:05

The W3 docs have a nested list example prefixed by DEPRECATED EXAMPLE:, but they never corrected it with a non-deprecated example, nor explained exactly what is

7条回答
  •  误落风尘
    2020-11-22 04:24

    Option 2 is correct: The nested

      is a child of the
    • it belongs in.

      If you validate, option 1 comes up as an error in html 5 -- credit: user3272456


      Correct:
        as child of

      The proper way to make HTML nested list is with the nested

        as a child of the
      • to which it belongs. The nested list should be inside of the
      • element of the list in which it is nested.

        • Parent/Item
          • Child/Subitem

        W3C Standard for Nesting Lists

        A list item can contain another entire list — this is known as "nesting" a list. It is useful for things like tables of contents, such as the one at the start of this article:

        1. Chapter One
          1. Section One
          2. Section Two
          3. Section Three
        2. Chapter Two
        3. Chapter Three

        The key to nesting lists is to remember that the nested list should relate to one specific list item. To reflect that in the code, the nested list is contained inside that list item. The code for the list above looks something like this:

        1. Chapter One
          1. Section One
          2. Section Two
          3. Section Three
        2. Chapter Two
        3. Chapter Three

        Note how the nested list starts after the

      • and the text of the containing list item (“Chapter One”); then ends before the
      • of the containing list item. Nested lists often form the basis for website navigation menus, as they are a good way to define the hierarchical structure of the website.

        Theoretically you can nest as many lists as you like, although in practice it can become confusing to nest lists too deeply. For very large lists, you may be better off splitting the content up into several lists with headings instead, or even splitting it up into separate pages.

提交回复
热议问题