SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2008
    Location
    Italy
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Pass markup validation with nested ul unsorted lists

    Hi,

    I have this code with nested unsorted lists

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
      <head>
      <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
      <title></title>
      </head>
      <body>
       <ul>
          <li>List 1</li>
             <ul>
                <li>Nested list #1</li>
                <li>Nested list #2</li>
             </ul>
          <li>List 2</li>
       </ul>
      </body>
    </html>
    How can I pass the markup validation?

    many thanks.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,175
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)
    The validator error message:
    Line 10, Column 13: document type does not allow element "UL" here; assuming missing "LI" start-tag
    isn't all that obvious I guess. What it means is that the nested list should be inside of a line item. i.e. move the closing /li from after "List 1" to after the closing /ul

  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A ul element can only contain li elements; nothing else. Thus the nested list must reside inside a list item of the outer list.

    Code HTML4Strict:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
      <head>
      <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
      <title></title>
      </head>
      <body>
       <ul>
          <li>List 1
             <ul>
                <li>Nested list #1</li>
                <li>Nested list #2</li>
             </ul>
          </li>
          <li>List 2</li>
       </ul>
      </body>
    </html>
    Birnam wood is come to Dunsinane


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •