views:

517

answers:

4

I know that DIV inside LI isn't allowed, but I've seen it lately on many "big" websites like: Smashing Magazine, Web Designer Wall... etc. I try to validate sites, and they have errors, but nothing about div's in LI?!

So can i use it inside LI, and I need it to be valid?

Thanks

+1  A: 

It is acceptable to place div inside a li, even if it is a block element (how else would we have nested lists?). I would like to see your source on why it isn't allowed!

akamike
Its block element, anyway... thanks :)
Kenan
+6  A: 

Yes it is valid according to xhtml1-strict.dtd. The following XHTML passes the validation:

<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Test</title>
</head>
<body>
<ul>
  <li><div>test</div></li>
</ul>
</body>
</html>
Darin Dimitrov
I'm using transitional
Kenan
It is still valid with `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">`.
Darin Dimitrov
A: 

I disagree with Superstringcheese,

Semantically, a DIV has no meaning

That's definitely not true. Check with W3C. For instance you wouldn't put a DIV inside a P, and that's precisely because a DIV has a semantic meaning.

Flower
+2  A: 

If you look at xhtml1-strict.dtd, you'll see

<!ELEMENT li %Flow;>
<!ENTITY % Flow "(#PCDATA | %block; | form | %inline; | %misc;)*">
<!ENTITY % block
     "p | %heading; | div | %lists; | %blocktext; | fieldset | table">

Thus div, p etc. can be inside li (according to XHTML 1.0 Strict DTD from w3.org).

Messa
That's true for the HTML 4.01 DTD as well.
Lazarus