{"id":2980,"date":"2010-02-03T15:26:23","date_gmt":"2010-02-03T21:26:23","guid":{"rendered":"http:\/\/cssnewbie.com\/?p=518"},"modified":"2010-02-03T15:26:23","modified_gmt":"2010-02-03T21:26:23","slug":"the-simple-secret-to-good-dropdown-navigation","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/the-simple-secret-to-good-dropdown-navigation\/","title":{"rendered":"The Simple Secret to Good Dropdown Navigation"},"content":{"rendered":"<p><a href=\"http:\/\/cssnewbie.com\/example\/horizontal-menu\/centered.html\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2009\/12\/centered-navbar-beauty.png\" alt=\"Centered Navigation Bar - Click to see it in action!\" title=\"Centered Navigation Bar - Click to see it in action!\" width=\"500\" height=\"100\" class=\"alignnone size-full wp-image-473\" \/><\/a><\/p>\n<p>Almost every example of good dropdown navigation on the web today relies on a single, simple HTML structure: the nested unordered list. Without this structure, dropdown menus would be much more complex to build than they already are.<\/p>\n<p>Of course, that means that knowing how to build a good nested unordered list is critical to this entire process. I\u2019ve seen many examples of people trying to build a dropdown menu on their own, running into problems they didn\u2019t understand, and throwing their hands up in frustration&#8230; only to discover their problem wasn\u2019t some obscure CSS problem, but an error in their list structure.<\/p>\n<p>As such, I thought it would be a good idea to go over what a good nested unordered list structure looks like (and what a bad one often looks like too!).<!--more--><\/p>\n<h3>The Good<\/h3>\n<p>Here\u2019s a well-structured nested unordered list &#8212; a perfect foundation for a dropdown menu.<\/p>\n<pre lang=\"html4strict\" escaped=\"true\" line=\"1\">&lt;ul id=&quot;navbar&quot;&gt;\n\t&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Nav Item 1&lt;\/a&gt;&lt;\/li&gt;\n\t&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Nav with Subnav&lt;\/a&gt;\n\t\t&lt;ul&gt;\n\t\t\t&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Subnav 1&lt;\/a&gt;&lt;\/li&gt;\n\t\t\t&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Subnav 2&lt;\/a&gt;&lt;\/li&gt;\n\t\t&lt;\/ul&gt;\n\t&lt;\/li&gt;\n\t&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Nav Item 3&lt;\/a&gt;\n&lt;\/ul&gt;<\/pre>\n<p>The critical detail in the example above is where the nested unordered list appears in relation to the list item it is \u201cunder\u201d. The unordered list is <strong>inside<\/strong> the list item that will act as its parent in the navigation. <\/p>\n<p>That\u2019s a very critical bit. Without that little detail, it becomes much more difficult to determine which submenus \u201cbelong\u201d to which main list items. <\/p>\n<h3>The Bad<\/h3>\n<p>By comparison, this is what I see 90% of the time when someone has a misbehaving menu:<\/p>\n<pre lang=\"html4strict\" escaped=\"true\" line=\"1\">&lt;ul id=&quot;navbar&quot;&gt;\n\t&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Nav Item 1&lt;\/a&gt;&lt;\/li&gt;\n\t&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Nav with Subnav&lt;\/a&gt;&lt;\/li&gt;\n\t&lt;ul&gt;\n\t\t&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Subnav 1&lt;\/a&gt;&lt;\/li&gt;\n\t\t&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Subnav 2&lt;\/a&gt;&lt;\/li&gt;\n\t&lt;\/ul&gt;\n\t&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Nav Item 3&lt;\/a&gt;\n&lt;\/ul&gt; <\/pre>\n<p>It\u2019s an extremely minor difference. The only change here is that the nested unordered list appears <strong>immediately after<\/strong> the list item they expect it to appear under, instead of <strong>directly inside<\/strong> like it should be.<\/p>\n<p>And that makes a difference, obviously, in our CSS and JavaScript.  Elements aren\u2019t where the CSS is looking for them, relationships are harder to determine in JavaScript, and so forth.<\/p>\n<h3>List-Based Navigation Menus<\/h3>\n<p>And since we are talking about list-based navigation menus, here are a few that have been discussed on CSS Newbie. All rely on unordered lists as their structure:<\/p>\n<ul>\n<li><a href=\"http:\/\/cssnewbie.com\/full-width-centered-navigation-bar\/\">A Full-Width Centered Navigation Bar<\/a><\/li>\n<li><a href=\"http:\/\/cssnewbie.com\/super-simple-horizontal-navigation-bar\/\">A Super Simple Horizontal Navigation Bar<\/a><\/li>\n<li><a href=\"http:\/\/cssnewbie.com\/horizontal-dropdown-menus\/\">Horizontal CSS Dropdown Menus<\/a><\/li>\n<li><a href=\"http:\/\/cssnewbie.com\/easy-css-dropdown-menus\/\">Easy CSS Dropdown Menus<\/a><\/li>\n<\/ul>\n<p>And with that, I\u2019ll be gone on vacation until next week. Take good care of the place, peeps!<\/p>\n<div class=\"wp-socializer wpsr-share-icons \" data-lg-action=\"show\" data-sm-action=\"show\" data-sm-width=\"768\" ><h3>Share and Enjoy !<\/h3><div class=\"wpsr-si-inner\"><div class=\"wpsr-counter wpsrc-sz-32px\" style=\"color:#000\"><span class=\"scount\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook,twitter,linkedin,pinterest,print,pdf\">0<\/span><\/span><small class=\"stext\">Shares<\/small><\/div><div class=\"socializer sr-popup sr-32px sr-circle sr-opacity sr-pad sr-count-1 sr-count-1\"><span class=\"sr-facebook\"><a rel=\"nofollow\" href=\"https:\/\/www.facebook.com\/share.php?u=\" target=\"_blank\"  title=\"Share this on Facebook\"  style=\"color: #ffffff\" ><i class=\"fab fa-facebook-f\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-twitter\"><a rel=\"nofollow\" href=\"https:\/\/twitter.com\/intent\/tweet?text=%20-%20%20\" target=\"_blank\"  title=\"Tweet this !\"  style=\"color: #ffffff\" ><i class=\"fab fa-twitter\"><\/i><\/a><\/span>\n<span class=\"sr-linkedin\"><a rel=\"nofollow\" href=\"https:\/\/www.linkedin.com\/sharing\/share-offsite\/?url=\" target=\"_blank\"  title=\"Add this to LinkedIn\"  style=\"color: #ffffff\" ><i class=\"fab fa-linkedin-in\"><\/i><\/a><\/span>\n<span class=\"sr-pinterest\"><a rel=\"nofollow\" href=\"https:\/\/www.pinterest.com\/pin\/create\/button\/?url=&amp;media=&amp;description=\" target=\"_blank\"  title=\"Submit this to Pinterest\"  style=\"color: #ffffff\" data-pin-custom=\"true\"><i class=\"fab fa-pinterest\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"pinterest\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-print\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Print this article \"  style=\"color: #ffffff\" ><i class=\"fa fa-print\"><\/i><\/a><\/span>\n<span class=\"sr-pdf\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Convert to PDF\"  style=\"color: #ffffff\" ><i class=\"fa fa-file-pdf\"><\/i><\/a><\/span><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Almost every example of good dropdown navigation on the web today relies on a single, simple HTML structure: the nested unordered list. Of course, that means that knowing how to build a good nested unordered list is critical to this entire process. [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/the-simple-secret-to-good-dropdown-navigation\/\" title=\"Click to read 'The Simple Secret to Good Dropdown Navigation'\">Read Article<\/a><\/p>\n","protected":false},"author":18,"featured_media":473,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[168,186,188,192],"tags":[89,88,365],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/2980"}],"collection":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/comments?post=2980"}],"version-history":[{"count":0,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/2980\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media\/473"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=2980"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=2980"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=2980"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}