{"id":137,"date":"2009-07-19T10:48:54","date_gmt":"2009-07-19T09:48:54","guid":{"rendered":"http:\/\/www.simonbattersby.com\/blog\/?page_id=137"},"modified":"2010-11-11T12:18:37","modified_gmt":"2010-11-11T11:18:37","slug":"building-a-css-vertical-expanding-menu-with-flyouts-stage-3","status":"publish","type":"page","link":"https:\/\/www.simonbattersby.com\/blog\/building-a-css-vertical-expanding-menu-with-flyouts-stage-3\/","title":{"rendered":"Building a css vertical expanding menu with flyouts &#8211; stage 3"},"content":{"rendered":"<p><a title=\"Part 2\" href=\"\/blog\/building-a-css-vertical-expanding-menu-with-flyouts-stage-2\/\">Click here for Part 2 <\/a><\/p>\r\n\r\n<p>First a word of warning. If by any chance you&#8217;re trying to follow this and using IE6, then first of all, it won&#8217;t work (but read on for a fix), and second of all, do yourself a big favour and install Firefox, or at least IE7.<\/p>\r\n\r\n<p>The css changes here are quite simple.To create the &#8220;flyout&#8221; behaviour I&#8217;m going to use the concept of absolute positioning. This will enable me to use css to exactly define where I want the flyout menu to appear, outside the normal flow definded by the html.<\/p>\r\n\r\n<p>I want to trigger this behaviour when the mouse is hovered over the appropriate top level menu button &#8211; so for example when I hover over the &#8220;Blog&#8221; menu button the second level menu should appear to the right of the Blog button, on top of any text.<\/p>\r\n\r\n<p>I need to make two additions to the css to make this work:<\/p>\r\n\r\n<pre>css\r\n\r\n#nav-menu ul\r\n {list-style-type:none;\r\n  margin:0px;\r\n  padding:0px}\r\n\r\n#nav-menu ul a\r\n{text-decoration:none;\r\n border:1px solid #303030;\r\n width:170px;\r\n display:block;\r\n text-align:center;\r\n font-size:14pt;\r\n line-height:2em;\r\n background:url(Images\/Buttons\/Button_top.gif) repeat-x left;\r\n font-family:Arial, Helvetica, sans-serif;\r\n color:white}\r\n\r\n#nav-menu ul ul\r\n{display:none} \r\n\r\nbody.blog #nav-menu ul ul.blog, \r\nbody.web #nav-menu ul ul.web\r\n{display:block}\r\n\r\n<span class=\"code_highlight\">#nav-menu ul li{position:relative}\r\n\r\n#nav-menu ul li:hover ul\r\n{display:block;\r\n position:absolute;\r\n left:172px;\r\n top:0px;}<\/span>\r\n\r\n#nav-menu ul ul li a\r\n{border:1px solid #888888;\r\n border-bottom: none;\r\n font-size:12pt;\r\n line-height: 1.6em;\r\n color:#303030;\r\n background-color:#a5a5a5;\r\n background-image:none;}<\/pre>\r\n\r\n<p>Let&#8217;s have a look at what I&#8217;ve done here. The statement<\/p>\r\n\r\n<code>#nav-menu ul li{position:relative}<\/code>\r\n\r\n<p>sets the reference point for my absolute positioning, in this case to be the position of the top level menu item. Once I&#8217;ve done this then the statement:<\/p>\r\n\r\n<code>#nav-menu ul li:hover ul{display:block;position:absolute;left:172px; top:0px;}<\/code>\r\n\r\n<p>displays the second level menu and positions it absolutely. Horizontally it&#8217;s positioned 172px to the left of the top level menu,  accounting for the 170px width and a 1px border on both sides. Vertically it is positioned at the same height as the top level menu. So, from the Home page if I hover over &#8220;Blog&#8221;  or &#8220;Websites&#8221; I get second level flyout. Give it a go below:<\/p>\r\n\r\n<div class=\"greybox\">\r\n<ul id=\"menu16\">\r\n<li><a href=\"#\">Home<\/a><\/li>\r\n<li><a href=\"#\">Blog<\/a>\r\n<ul>\r\n<li><a href=\"#\">Blog 1<\/a><\/li>\r\n<li><a href=\"#\">Blog 2<\/a><\/li>\r\n<\/ul>\r\n<\/li>\r\n<li><a href=\"#\">Websites<\/a>\r\n<ul>\r\n<li><a href=\"#\">Websites 1<\/a><\/li>\r\n<li><a href=\"#\">Websites 2<\/a><\/li>\r\n<\/ul>\r\n<\/li>\r\n<li><a href=\"#\">Photos<\/a><\/li>\r\n<\/ul>\r\n<\/div>\r\n\r\n<p>I&#8217;m not quite finished yet, because I don&#8217;t want a flyout menu if I hover over a top level menu on a page where I&#8217;m already displaying the second level menu. Sorting this out is quite easy using the classes I defined earlier. I just need to add to the css:<\/p>\r\n\r\n<pre>css\r\n\r\n#nav-menu ul\r\n {list-style-type:none;\r\n  margin:0px;\r\n  padding:0px}\r\n\r\n#nav-menu ul a\r\n{text-decoration:none;\r\n border:1px solid #303030;\r\n width:170px;\r\n display:block;\r\n text-align:center;\r\n font-size:14pt;\r\n line-height:2em;\r\n background:url(Images\/Buttons\/Button_top.gif) repeat-x left;\r\n font-family:Arial, Helvetica, sans-serif;\r\n color:white}\r\n\r\n#nav-menu ul ul\r\n{display:none} \r\n\r\nbody.blog #nav-menu ul ul.blog, \r\nbody.web #nav-menu ul ul.web,\r\nbody.web #nav-menu ul li:hover ul.web<span class=\"code_highlight\">,\r\nbody.blog #nav-menu ul li:hover ul.blog<\/span> \r\n{display:block<span class=\"code_highlight\">;position:relative;left:0px<\/span>}\r\n\r\n#nav-menu ul li{position:relative}\r\n\r\n#nav-menu ul li:hover ul\r\n{position:absolute;\r\n display:block;\r\n left:172px;\r\n top:0px;}\r\n\r\n#nav-menu ul ul li a\r\n{border:1px solid #888888;\r\n border-bottom: none;\r\n font-size:12pt;\r\n line-height: 1.6em;\r\n color:#303030;\r\n background-color:#a5a5a5;\r\n background-image:none;}<\/pre>\r\n\r\n<p>What the css is saying here is that when I&#8217;m hovering over, for example &#8220;Blog&#8221; but on a page with class of &#8220;blog&#8221; then the second level menu should be positioned as normal, not as a flyout. This will take precedence over the earlier statement because it specifically applies to the blog page.<\/p>\r\n\r\n<p>So, if you&#8217;re designing for IE7+, Firefox, Opera, Chrome or Safari, that&#8217;s all there is to it.<\/p>\r\n\r\n<p>Sadly, however, some (most?) people need to take IE6 into account. This will not work on IE6 without a tweakette because IE6 does not support the hover behaviour except on links. There is a little widget that will take care of this however, called csshover, which you&#8217;ll find <a title=\"csshover widget\"href=\"http:\/\/www.xs4all.nl\/~peterned\/csshover.html\">here<\/a> along with instructions on how to use it. I&#8217;ve personally found version 2 of this software to be the most reliable.<\/p>\r\n\r\n<p>If you&#8217;ve got this far, I hope you&#8217;ve found these few pages useful. If you&#8217;ve got any suggestions for improving either the css or the article, let me know.<\/p>","protected":false},"excerpt":{"rendered":"<p>Click here for Part 2 First a word of warning. If by any chance you&#8217;re trying to follow this and using IE6, then first of all, it won&#8217;t work (but read on for a fix), and second of all, do yourself a big favour and install Firefox, or at least IE7. The css changes here [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-137","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/pages\/137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/comments?post=137"}],"version-history":[{"count":0,"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/pages\/137\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/media?parent=137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}