By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,625 Members | 2,235 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,625 IT Pros & Developers. It's quick & easy.

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

P: n/a
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 <ulfor the nested list should not be there.
Removing the </liimmediately prior to the nested <ulsorts 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 </liimmediately 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 </libefore 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>

Mar 31 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Els
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 <ulfor the nested list should not be there.
iCab is correct.
Removing the </liimmediately prior to the nested <ulsorts 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 </liimmediately 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 </libefore 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 </liafter the nested <ul>?
A nested list, is a child of a list item.
--
Els http://locusmeus.com/
accessible web design: http://locusoptimus.com/
Mar 31 '07 #2

P: n/a
On Mar 31, 2007 Els wrote:
See the closing </liafter the nested <ul>?
A nested list, is a child of a list item.
Thank you. I didn't notice the closing </liafter nested <uland that's
where I went wrong :)

It seems that the nested <ulis a child of the <lias 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>

Mar 31 '07 #3

P: n/a
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 </libefore 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
Mar 31 '07 #4

P: n/a
Els <el*********@tiscali.nlwrote:
news: k7****************************@40tude.net
patrick j wrote:
[snip]
>Removing the </liimmediately prior to the nested <ulsorts this
out, so iCab is happy with what is below:
[snip]
>But it doesn't seem to make sense to leave out that </libefore 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*

Mar 31 '07 #5

P: n/a
Els
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/
Mar 31 '07 #6

P: n/a
patrick j wrote:
</ul
Fix this first.

</ul>
Mar 31 '07 #7

P: n/a
On 31 Mar, 12:29, patrick j <usemywebs...@googlemail.comwrote:
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, <por another nested
<ulneeds 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 <ulis <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. <uljust 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 </liare (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>

Apr 2 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.