Nested lists

Discussion in 'HTML & Website Design' started by fadetoblack22, Aug 7, 2009.

  1. #1
    I am trying to make a nested list, but I can't make it more than one stage of nesting.

    I have put an example below. If I put another <ul> under "dog" and list types of dog, it does't work. Does anyone know why this is?

    <ul>

    <li><a href="#">Animals</a>
    <ul>
    <li><a href="#">Dog</a></li>
    <li><a href="#">Cat</a></li>
    <li><a href="#">Fish</a></li>
    </ul>

    </ul>
     
    fadetoblack22, Aug 7, 2009 IP
  2. Kazumael

    Kazumael Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I don't see any problems with the following code in Firefox or Safari:



    
    
    <ul>
    <li><a href="#">Animals</a>
     
    <ul>
    <li><a href="#">Dog</a></li>
    	
    <ul>
    <li><a href="#">Chihuahua</a></li>
    <li><a href="#">Pitbull</a></li>
    <li><a href="#">Beagle</a></li>
    </ul>
    
    <li><a href="#">Cat</a></li>
    <li><a href="#">Fish</a></li>
    </ul>
    
    </ul>
    
    HTML:
     

    Attached Files:

    Kazumael, Aug 7, 2009 IP
  3. 1 FineLine

    1 FineLine Peon

    Messages:
    78
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    looks good to me

    
    <ul>
       <li><a href="#">Animals</a>
          <ul>
             <li><a href="#">Dog</a>
                <ul>
                   <li>new list</li>
                </ul>
             </li>
             <li><a href="#">Cat</a></li>
             <li><a href="#">Fish</a></li>
          </ul>
        </li>
    </ul> 
    
    Code (markup):
     
    1 FineLine, Aug 7, 2009 IP
  4. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #4
    Should each stage of nesting indent in? Because mine don't.
     
    fadetoblack22, Aug 7, 2009 IP
  5. 1 FineLine

    1 FineLine Peon

    Messages:
    78
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    no.

    indenting just helps with cleanliness. I find it easier to decipher code if it's indented. Especially if you have an unclosed tag somewhere.
     
    1 FineLine, Aug 7, 2009 IP
  6. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #6
    I mean in the outputted code.
     
    fadetoblack22, Aug 7, 2009 IP
  7. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #7
    fade to black
    your original code was missing a tag

    you opened your li
    and had the a inside it
    and then opened your sub ul
    and had the inner list
    and closed the sub ul

    but you never then also closed the li who was holding the sub ul inside it.

    </ul>
    </ul>
    This is what catches the eye. Since a ul can't have anyone other than a li as a direct child, not even another ul, you know there's something wrong when you have to closing ul tags like that

    so insert a </li> between them
     
    Stomme poes, Aug 7, 2009 IP
  8. twistedspikes

    twistedspikes Notable Member

    Messages:
    5,694
    Likes Received:
    293
    Best Answers:
    0
    Trophy Points:
    280
    #8
    Can't say I can remember off the top of my head if the indentation is kept for sub-lists or not but I'd think not. The indentation (if you want it to indent further) will depend on the CSS you apply to the lists.
     
    twistedspikes, Aug 7, 2009 IP
  9. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #9
    I've worked it out now guys. I had closed the <li> before the nested part.
     
    fadetoblack22, Aug 8, 2009 IP