Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>With a bit modified HTML and javascript the following menu works well (tested with IE7-10, Chrome, Firefox, Opera and Safari):</p> <p>HTML</p> <pre class="lang-html prettyprint-override"><code>&lt;div id="menu-container" class="full-width"&gt; &lt;div class="full-width-bg"&gt;&lt;/div&gt; &lt;!-- this additional div makes red background --&gt; &lt;ul class="main-menu normal-width"&gt; ... etc ... &lt;/ul&gt; &lt;/div&gt; </code></pre> <p>CSS</p> <pre class="lang-css prettyprint-override"><code>.full-width { width: 100%; background: orange; border:1px solid green; position:relative; z-index:1; height:3em; font-size:21px; } .full-width-bg { width:100%; background: red; height:50%; position:absolute; left:0; top:0; z-index:2; } .normal-width { width: 1024px; margin: 0 auto; z-index:3; position:relative; } .full-width, .full-width-bg { min-width: 1024px; } ul.main-menu li { float:left; padding:0; margin:0; height:100%; position:static; text-align:center; } ul.main-menu, ul.main-menu ul { list-style-type:none; height: 1.5em; margin: 0 auto; padding: 0; } ul.main-menu a { text-decoration:none; display:inline-block; *display:inline; zoom:1; /* IE7 fix */ width:100%; padding:0; max-height: 1.5em; } ul.main-menu &gt; li { background-color:red; } ul.main-menu &gt; li &gt; ul &gt; li { background-color:orange; } ul.main-menu &gt; li &gt; ul &gt; li:hover { background-color:yellow; } ul.main-menu &gt; li &gt; ul &gt; li:hover &gt; a { color:red; } ul.main-menu &gt; li &gt; ul { position:absolute; top:100%; left:0px; width:100%; } .main-menu &gt; li.selected, ul.main-menu &gt; li:hover &gt; a { background-color:#d00; color:white; } ul.main-menu &gt; li &gt; ul { display:none; z-index:4; } ul.main-menu &gt; li:hover &gt; ul { display:block; z-index:5; } </code></pre> <p>jQuery</p> <pre class="lang-js prettyprint-override"><code>$(function () { var items = $('.main-menu&gt;li'); var maxitems = 5; //items.length; var current = items[0]; $('.main-menu li').css('width', (100 / maxitems | 0) + '%'); items.mouseenter(function(e) { $(current).removeClass('selected').children('ul').hide(); current = this; $(current).addClass('selected').children('ul').show(); }); items.children('ul').show().end().eq(0).trigger('mouseenter'); }); </code></pre> <p><a href="http://jsfiddle.net/X7T94/12/show" rel="nofollow">JSFiddle</a>: <a href="http://jsfiddle.net/X7T94/12/" rel="nofollow">http://jsfiddle.net/X7T94/12/</a> - this main menu reserves place for 5 menu links (see javascript)</p>
 

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