Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > The </li> before a nested list. Why not?

Reply
Thread Tools

The </li> before a nested list. Why not?

 
 
patrick j
Guest
Posts: n/a
 
      03-31-2007
Hi

I'm wondering about lists with nested lists as one does on a Saturday
afternoon.

Anyway below is an example of a list with a nested list which the iCab
browser's very useful HTML verification ability will not like:

<ul>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
<ul>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
</ul
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
</ul>

iCab complains that the <ul> for the nested list should not be there.
Removing the </li> immediately prior to the nested <ul> sorts this out, so
iCab is happy with what is below:

<ul>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
<li><a href="#">link</a>
<ul>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
</ul
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
</ul>

I notice that at the rather excellent Max Design tutorials on lists they
leave out the </li> immediately prior to a nested list.

You can see this here:

<http://css.maxdesign.com.au/listamatic2/vertical01.htm>

So it would suggest it's not just the iCab verification system that doesn't
like it.

But it doesn't seem to make sense to leave out that </li> before the nested
list.

I'd be grateful if someone could explain why it is so?

Thank you



--
Patrick - Brighton, UK
If you wish email me from my web-site: <http://www.patrickjames.me.uk>
Inventory service in Sussex: <http://www.inventoryworks.co.uk>

 
Reply With Quote
 
 
 
 
Els
Guest
Posts: n/a
 
      03-31-2007
patrick j wrote:

> Anyway below is an example of a list with a nested list which the iCab
> browser's very useful HTML verification ability will not like:
>
> <ul>
> <li><a href="#">link</a></li>
> <li><a href="#">link</a></li>
> <li><a href="#">link</a></li>
> <ul>


Oops! Bad code

> iCab complains that the <ul> for the nested list should not be there.


iCab is correct.

> Removing the </li> immediately prior to the nested <ul> sorts this out, so
> iCab is happy with what is below:

[snip]
> <li><a href="#">link</a>
> <ul>
> <li><a href="#">link</a></li>

[snip]
> </ul
> <li><a href="#">link</a></li>


If iCab likes that, it's missing a spot..

> I notice that at the rather excellent Max Design tutorials on lists they
> leave out the </li> immediately prior to a nested list.


No, they don't leave it out - they place it in the right place.

> You can see this here:
>
> <http://css.maxdesign.com.au/listamatic2/vertical01.htm>


Exactly. That's correct code

> So it would suggest it's not just the iCab verification system that doesn't
> like it.


True.

> But it doesn't seem to make sense to leave out that </li> before the nested
> list.


It does. The nested ul is not nested if it's not inside the <li>
element.
The correct code is:
<ul>
<li>....</li>
<li>....
<ul>
<li>...</li>
<li>...</li>
</ul>
</li>

etc.

See the closing </li> after the nested <ul>?
A nested list, is a child of a list item.


--
Els http://locusmeus.com/
accessible web design: http://locusoptimus.com/
 
Reply With Quote
 
 
 
 
patrick j
Guest
Posts: n/a
 
      03-31-2007
On Mar 31, 2007 Els wrote:

> See the closing </li> after the nested <ul>?
> A nested list, is a child of a list item.


Thank you. I didn't notice the closing </li> after nested <ul> and that's
where I went wrong

It seems that the nested <ul> is a child of the <li> as you say. I had
originally thought it would be a child of the not-nested <ul>.

I learn something every day

--
Patrick - Brighton, UK
If you wish email me from my web-site: <http://www.patrickjames.me.uk>
Inventory service in Sussex: <http://www.inventoryworks.co.uk>

 
Reply With Quote
 
Bergamot
Guest
Posts: n/a
 
      03-31-2007
patrick j wrote:
>
> <li><a href="#">link</a></li>
> <ul>


The above is invalid syntax, as any HTML validator will tell you.

> But it doesn't seem to make sense to leave out that </li> before the nested
> list.


Yes, it does. As Els said, the nested list is part of the parent <li>,
not separate from it. That's what makes it nested, not merely the
placement of the child <ul>.

> I'd be grateful if someone could explain why it is so?


The reason you see so much of the invalid syntax version is because many
"WYSIWYG" tools don't generate correct syntax for nested lists. The only
reason it doesn't look broken on screen is because of browser error
correction.

--
Berg
 
Reply With Quote
 
BootNic
Guest
Posts: n/a
 
      03-31-2007
> Els <(E-Mail Removed)> wrote:
> news: http://www.velocityreviews.com/forums/(E-Mail Removed)
> patrick j wrote:
>

[snip]
>> Removing the </li> immediately prior to the nested <ul> sorts this
>> out, so iCab is happy with what is below:

[snip]
>> But it doesn't seem to make sense to leave out that </li> before the
>> nested list.

[snip]

As a side note, the li start tag is required, the end tag: optional.

http://www.w3.org/TR/html401/struct/lists.html

--
BootNic Saturday, March 31, 2007 11:17 AM

When men are pure, laws are useless; when men are corrupt, laws are
broken.
*Benjamin Disraeli*

 
Reply With Quote
 
Els
Guest
Posts: n/a
 
      03-31-2007
BootNic wrote:

> As a side note, the li start tag is required, the end tag: optional.
>
> http://www.w3.org/TR/html401/struct/lists.html


In HTML, yes. In XHTML, no.

--
Els http://locusmeus.com/
accessible web design: http://locusoptimus.com/
 
Reply With Quote
 
zzpat
Guest
Posts: n/a
 
      03-31-2007
patrick j wrote:

> </ul


Fix this first.

</ul>
 
Reply With Quote
 
Andy Dingley
Guest
Posts: n/a
 
      04-02-2007
On 31 Mar, 12:29, patrick j <(E-Mail Removed)> wrote:

> I'm wondering about lists with nested lists as one does on a Saturday
> afternoon.


Don't wonder, read the DTD and _know_.

You can't (validly) put anything inside a <ul> (or <ol>) except
<li>. So _anything_ you put in there, text, <p> or another nested
<ul> needs to go inside <li>. Not "adjacent to" or "after" <li>, but
contained wholly inside it.

It's SGML, so closing elements are generally optional. As the parser
"knows" that the only thing allowed inside <ul> is <li>, then it can
assume several things about the document, even if the literal </li>
tags have (correctly and optionally) been omitted.

<ul><li></li><ul>...
is clearly invalid. <ul> just can't be a child of <ul>.

<ul><li></li><li><ul>...</ul></li>
is valid. Containment is satisfied and the things that are children in
the document are permitted to be children by the DTD

<ul><li><li><ul>...</ul><li>...
is also valid. Some </li> are (permissibly) omitted. An SGML parser
can automatically generate a document tree from this that's equivalent
to having parsed the following document:

<ul>
<li></li>
<li>
<ul>...</ul>
</li>
<li>...</li>
</ul>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
nested web control postback selections not updated before page_load brad ASP .Net 2 02-07-2007 01:45 PM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Before Sunset & Before Sunrise matt r DVD Video 2 11-25-2004 08:37 AM
XML TRANSFORM - Serious problem - nested element causes Index error...why oh why??? KathyB ASP .Net 0 06-24-2003 07:37 PM



Advertisments