views:

439

answers:

3

http://www.webdesignfromscratch.com/html-css/html-lists.php on this page's example of nested Unordered lists <ul> list's code is not validating on W3C validation

this is a code of this page http://www.webdesignfromscratch.com/html-css/html-lists.php

<ul>
  <li>Item one</li>
  <li>Item two</li>
  <li>Watch, you can easily nest list items: This item has some sub-items</li>
  <ul>
    <li>Sub-item one</li>
    <li>Sub-item two</li>
    <li>Shall we do a 3rd nested list?</li>
    <ul>
      <li>OK</li>
      <li>Your browser should automatically use different bullet styles for each level.</li>
    </ul>
  </ul>
</ul>

website owner should test code validity before and after writing code

+10  A: 

The nested <ul> should be inside the <li>.

Max Shawabkeh
+6  A: 

Because due to XHTML (and probably also due to HTML 4), nested <ul> must be a child of <li>

Example:

<ul>
  <li> Here is level 1
    <ul>
      <li> Bla bla (level 2) </li>
    </ul>
  </li>
</ul>

looks like:

  • Here is level 1
    • Bla bla (level 2)

Edit: link: http://www.w3schools.com/XHTML/xhtml_html.asp
Edit: prepared spec for html5: http://www.w3.org/MarkUp/html-spec/html-spec_5.html#SEC5.6 also shows how to make nesting valid

Adam Kiss
It does apply to HTML 4 too. The W3Schools link you provide is irrelevant (and wrong) though. This has nothing to do about "An element must be entirely inside its parent", simply that ul may not be a child of ul.
David Dorward
w3schools link I provided is simply for another example, thank you for clarification though. For me it's just one of those things "i do" :]
Adam Kiss
+2  A: 

Your sub-list(s) must be enclosed in a li tag.

i.e.

<ul>
  <li>Item one</li>
  <li>Item two</li>
  <li>Watch, you can easily nest list items: This item has some sub-items
  <ul>
    <li>Sub-item one</li>
    <li>Sub-item two</li>
    <li>Shall we do a 3rd nested list?
    <ul>
      <li>OK</li>
      <li>Your browser should automatically use different bullet styles for each level.</li>
    </ul></li>
  </ul></li>
</ul>
Chris
It's quite frustrating to not only have someone beat you to it, but write almost word-for-word what you were going to. :)
DK