Note that there are some explanatory texts on larger screens.

plurals
  1. POSpecial Drop-Down Menu
    primarykey
    data
    text
    <p>I am trying to achieve a simple drop-down menu with the following HTML structure. This structure is mandatory (I think) as explained in the illustrations below.</p> <pre><code>&lt;nav role="navigation"&gt; &lt;ul id="main-menu" class="nav top-nav clearfix"&gt; &lt;li id="menu-item-1" class="menu-item"&gt;&lt;a href="#"&gt;Menu 1&lt;/a&gt;&lt;/li&gt; &lt;li id="menu-item-2" class="menu-item"&gt;&lt;a href="#"&gt;Menu 2&lt;/a&gt;&lt;/li&gt; &lt;li id="menu-item-3" class="menu-item"&gt;&lt;a href="#"&gt;Menu 3&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;ul id="sub-menu-1" class="sub-menu nav clearfix"&gt; &lt;li class="menu-item"&gt;&lt;a href="#"&gt;Sub Menu 1.1&lt;/a&gt;&lt;/li&gt; &lt;li class="menu-item"&gt;&lt;a href="#"&gt;Sub Menu 1.2&lt;/a&gt;&lt;/li&gt; &lt;li class="menu-item"&gt;&lt;a href="#"&gt;Sub Menu 1.3/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;ul id="sub-menu-2" class="sub-menu nav clearfix"&gt; &lt;li class="menu-item"&gt;&lt;a href="#"&gt;Sub Menu 2.1&lt;/a&gt;&lt;/li&gt; &lt;li class="menu-item"&gt;&lt;a href="#"&gt;Sub Menu 2.2&lt;/a&gt;&lt;/li&gt; &lt;li class="menu-item"&gt;&lt;a href="#"&gt;Sub Menu 2.3/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/nav&gt; </code></pre> <p>To get a better idea of what I am trying to achieve I've made the following illustrations:</p> <ol> <li>Simple menu with items arranged with inline blocks. As you can see, the menu scales to 100% of the container and has all the items arranged in center.</li> </ol> <p><img src="https://i.stack.imgur.com/hbnmi.jpg" alt="This is how the menu looks when the mouse is not hovering any menu item"></p> <ol start="2"> <li>When hovering over a menu item which has a submenu. In the illustration that's Menu 1 which has Sub Menu 1 and it needs to display it on mouse hover, like a simple <code>&lt;ul&gt;&lt;li&gt;&lt;ul&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;</code> would do. As you can see the submenu has to scale to 100% of the container and has all the items arranged in center.</li> </ol> <p><img src="https://i.stack.imgur.com/TcygF.jpg" alt="When hovering over one item with a submenu"></p> <p>I think the best approach is with javascript (not sure you can do this with only CSS), but I am kind off stuck. The sub menu appears on main menu item hover, but as soon as I hover out into the sub menu in order to navigate, the sub menu disappears. Anyway, this is the javascript:</p> <pre><code>$('nav #main-menu .menu-item a').hover( function() { var id = $(this).parent().attr('id'); id = id.substr(id.length - 1); submenu = $('#sub-menu-' + id); submenu.show(); }, function() { var id = $(this).parent().attr('id'); id = id.substr(id.length - 1); submenu = $('#sub-menu-' + id); submenu.hide(); } ); </code></pre> <p>I am pretty sure that there is a better way to do this.</p> <p>I've also set up a <a href="http://jsfiddle.net/3z8MR/4/" rel="nofollow noreferrer">FIDDLE</a> for better understanding.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload