Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use div as a direct child of UL?

Tags:

html

css

I'm having this code:

<ul>    <div>    </div> </ul> 

I feel no issue in my browser rendering it. I have read this too somewhere that li should only be used as direct child of ul.

Is this correct? Can't I use div as a direct child of UL? Is there any documentation for the above confusion?

Edit: This link says I can http://css-tricks.com/forums/discussion/11593/divs-inside-uls/p1

like image 698
Rocky Singh Avatar asked Aug 01 '12 08:08

Rocky Singh


People also ask

Can you nest a div inside a UL?

html - Div cannot be nested inside ul and li cannot be nested inside div - Stack Overflow. Stack Overflow for Teams – Start collaborating and sharing organizational knowledge.

Can div be child of table?

No, you cannot insert a div directly inside of a table.

Should I use div or UL?

They're just tags. There's zero difference whatsoever between them DOM-wise; the only difference is in the rendering (CSS, which you can customize either way) and the meaning (semantics). If you have a list of things, use a <ul> .


2 Answers

No. The only element that may be a child of <ul> is <li>.

HTML 4:

<!ELEMENT UL - - (LI)+                 -- unordered list --> 

(See also how to read a content model definition in a DTD)

HTML 5:

Content model: Zero or more li elements.

like image 149
Quentin Avatar answered Sep 18 '22 00:09

Quentin


For HTML 5 :

http://www.w3.org/TR/html-markup/ul.html

Permitted contents

Zero or more li elements

For HTML 4 :

http://www.w3.org/TR/html401/struct/lists.html#h-10.2

<!ELEMENT UL - - (LI)+ 

EDIT :

I forget the other HTML5 :D (which have the same specification on this than the W3C's one)

http://www.whatwg.org/specs/web-apps/current-work/multipage/grouping-content.html#the-ul-element

like image 39
Shikiryu Avatar answered Sep 20 '22 00:09

Shikiryu