views:

308

answers:

3

I’ve seen some people wrap their navigation (<ul> tag) inside a <div>, and the <div> just has margin/padding CSS properties applied to it.

We can just style the navigation without a <div> and put the margin and padding on the <ul> tag. So it is necessary to put the <ul> tag inside the <div>, or is it just personal preference/favor?

And for HTML5 which has been implemented in some browsers, is it necessary to put the <ul> tag used for navigation in a <nav> tag?

Like e.g. the Smashing HTML5 demo page.

A: 

No, it is not necessary but it depends on the layout. The <div> provides more controller over the positioning of the document segments so probably they are just using div for that purpose.

Sarfraz
+1  A: 

If you’re producing HTML5, and you don’t mind working around Internet Explorer’s lack of support for the new elements in HTML5, then you should wrap your navigation in a <nav> element.

(Just like you should wrap your paragraphs in a <p> element — that’s what markup is, describing content by wrapping it with tags.)

As for wrapping your navigation list in a <div>, you don’t have to, but it’s often useful for styling purposes.

Paul D. Waite
A: 

been test for a day and wrap in and really provide "more styling" and "controller over the positioning of the document segments", thank for the answer.

dev