Best IT Recipes

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
html html5 validation html-lists xhtml
Vimal Basdeo Jun 23 2018-11-11T00: 00Z
source share
5 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 share

Inside <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 share

Because <li> is a block element, not an inline element of type <span> or <a> .

+8
twsaef Jun 23 2018-11-11T00: 00Z
source share

An <li> is a block element and will work perfectly with other block elements inside.

+6
Adam Jun 23 2018-11-11T00: 00Z
source share

Yes, you can. How many you want.

+4
Jose Faeti Jun 23 2018-11-11T00: 00Z
source share


More articles:

  • Android N not sending broadcast android.net.conn.CONNECTIVITY_CHANGE? - android
  • Get list from set in python - python
  • How can I improve my first user script? - javascript
  • Download files and store them locally using Phonegap / jQuery Mobile Android and iOS Apps - android
  • Jsoup message and cookie - java
  • How to get image size from file name - c #
  • What is the most efficient library / method for interaction between node.js processes? - javascript
  • JSOUP adds additional coded materials for html - java
  • Facebook login via Jsoup - java
  • How to crawl a site after entering it with username and password - java

All Articles

Geek Cook | 2019