Why is the following code valid when I am using a <div>
inside a <li>
?
<ul>
<li class="aschild">
<div class="nav">Test</div>
</li>
</ul>
Why is the following code valid when I am using a <div>
inside a <li>
?
<ul>
<li class="aschild">
<div class="nav">Test</div>
</li>
</ul>
An
<li>
is a block element, and will work perfectly fine with other block elements inside.Inside a
<li>
you can have anything you could naturally put inside a<div>
. They are no different in this sense.It should be valid in HTML4, XHTML and HTML5 as well.
This is NOT valid though (so the sources you found about "no divs in lists" could refer to this situation):
So: Lists (
ul
,ol
) can only haveli
s as their children. Butli
s can have anything as their children.Because
<li>
is a block element, not an inline element like<span>
or<a>
.Yes, you can. As much as you want.
Yes you can use a div inside a li and it will validate.