What is the most appropriate content to put in the header or Nav?

Asked

Viewed 2,803 times

2

I’m creating a page that has her logo and name on header, and a menu with links to other pages using lists on nav, but I’m not putting nav within the header, I put them all inside a div with a class menu, is it right to do it this way? or would it be better to put the nav inside header, and instead of me using the div, use a section?

2 answers

2


Right or wrong in this case does not exist. There is recommended according to the specifications of HTML5.

In the HTML4 by the fact of all semantic sections with the tag <div> are part of the document structure, there are no ways to have sections containing information related not to the document itself, but to the site in general, such as logos, menus, content tables, copyright or legal notices. For that purpose, the HTML5 introduces three new elements:

  • <nav> for link collections (such as a table of contents)
  • <footer> and <header> for information related to the website.

Realize that <footer> and <header> are not section contents like the <section>, instead, they exist to delimit semantically parts of a section.


Returning now to your universe, the tag Nav is commonly used to create menus as it represents a set of links. So yes you do well to use it in your menu.
How to put it inside the tag header, is entirely up to you, as the menu somehow represents the structure of your site, and fits the recommended content for that tag "information related to the website".
Finally, on the use Section or instead of div, this can be a good practice, if the div in question represents a section of your website. Example:

<div class="corpo-da-pagina">
    <!-- Todo o conteúdo da sua página -->
</div>

In the above case it would be recommended according to the specifications of the HTML5 tag section.

1

Are you wearing any framework?? guy boostrap or some other? If you have, you have to check their documentation, because every framework follows a hyena along with CSS If you don’t follow it may get messy on your screen.

If you are not using anything, creating everything from 0, there is no wrong way to do it, it can be in div as can be within specific tags like header, this will be just a matter of organizing your code. But the q will make the difference is the q mode you will handle everything in your style.

  • In fact, I believe what he’s trying to say is semantica

  • So it’s hard to answer without knowing what he’s really doing and what he’s using. I have page structures q created, where I use the header only for the logo and little information, and the Nav inside other Divs, or vice versa. It all depends even on the result q he wants to display on the screen and the organization of the codes with or without frameworks. At least that’s how I see it.

  • In fact, semantics does have a structure to follow https://www.w3schools.com/html/html5_semantic_elements.asp

Browser other questions tagged

You are not signed in. Login or sign up in order to post.