Can I use a div inside a list item?
Why is the following code valid when I use a <div> inside a <li> ?
<ul> <li class="aschild"> <div class="nav">Test</div> </li> </ul> +42
Vimal Basdeo Jun 23 2018-11-11T00: 00Z
source share5 answers
Yes, you can use the div inside li and it will check.
<!ELEMENT li %Flow;> <!ENTITY % Flow "(#PCDATA | %block; | form | %inline; | %misc;)*"> <!ENTITY % block "p | %heading; | div | %lists; | %blocktext; | fieldset | table"> +47
Jawad Jun 23 2018-11-11T00: 00Z
source shareInside <li> you can have everything you could put inside a <div> . In this sense, they are no different.
It must be correct in HTML4, XHTML and HTML5.
This is NOT valid (so the sources you found about "no divs in lists" may reference this situation):
<ul> <li></li> <div></div> <li></li> </ul> So: Lists ( ul , ol ) can only have li as their children. But li may have something like her children.
+28
kapa Jun 23 2018-11-11T00: 00Z
source shareBecause <li> is a block element, not an inline element of type <span> or <a> .
+8
twsaef Jun 23 2018-11-11T00: 00Z
source shareAn <li> is a block element and will work perfectly with other block elements inside.
+6
Adam Jun 23 2018-11-11T00: 00Z
source shareYes, you can. How many you want.
+4
Jose Faeti Jun 23 2018-11-11T00: 00Z
source share