title: HTML Select Drop Down Option Z-index
body: <p>I have a simple select drop down when I am going to select an option there is Menu navigation item, so now when I am going to hover on menu items navigation is going back to select option list which is open. It's happening in all browsers. I don't know whether it's a bug or what. Steps are:</p>
  
  <ul>
  <li>Open select dropdown options</li>
  <li>Same time hover on navigation menu items</li>
  <li>Now the navigation items are going behind the option list (not behind the select tag)</li>
  </ul>
  
  <p>I have tried giving z-index with positions. But nothing is working. I think its not an issue but need explanation on same. Any suggestions will be greatly appreciated.</p>
  
  <p>This is the sample code:</p>
  
  <pre><code>    &lt;style type="text/css"&gt;
  /* ####################   Navigation bar CSS styling   ################## */
  
  .mynavbar {
      position: relative;
    width: 100%;
    height: 23px; /* corresponds to 'line-height' of a.navbartitle below */
    margin: 0; border: 0; padding: 0;
    background-color: #666633;
  }
  
  
  a.navbartitle {
    display: block;
    float: left;
    color: white;
    background-color:  #666633;
    font-family: Verdana, Arial, Geneva,  Helvetica, sans-serif;
    font-size: 12px;
    font-weight: bold;
    margin: 0; border: 0; padding: 0;
    line-height: 23px; /* corresponds to 'top' value of .submenu below */
    text-align: center;
    text-decoration:none;
  }
  a.navbartitle:hover {
    background-color: #447755;
  }
  /* menu title widths */
  #t1 { width: 104px; }
  #t2 { width: 100px; }
  #t3 { width: 102px; }
  #t4 { width: 102px; }
  #t5 { width: 180px; }
  /* We just specify a fixed width for each menu title. Then, down below we specify
      a fixed left position for the corresponding submenus (e.g. #products_submenu, etc.)
      Using these fixed values isn't as elegant as just letting the text of each
      menu title determine the width of the menu titles and position of the submenus,
      but we found this hardwired approach resulted in fewer cross-browser/cross-OS
      formatting glitches -- and it's pretty easy to adjust these title widths and the
      corresponding submenu 'left' positions below, just by eyeballing them whenever
      we need to change the navbar menu titles (which isn't often). */
  
  .submenu {
      position:absolute;
    z-index: 2;
    top: 23px; /* corresponds to line-height of a.navbartitle above */
    padding: 0; margin: 0;
      width:166px; /* If adjust this, then adjust width of .submenu below a too */
      color: white;
      background-color:  #666633;
      border: 1px solid #447755; /* box around entire sub-menu */
    font-family: Verdana, Arial, Geneva,  Helvetica, sans-serif;
      font-size: 11px;
  }
  /* Fix IE formatting quirks. */
  * html .submenu { width: 148px; } /* IE needs narrower than width of .submenu above */
  /* End */
  
  /* position of each sub menu */
  /* We just eyeball the position of each submenu here -- can move left or right as needed.
     If you adjust menu title text, you might want to adjust these too. */
  #products_submenu {  left: 0px; visibility: hidden;  }
  #services_submenu {  left: 104px; visibility: hidden;  }
  #funstuff_submenu {  left: 204px; visibility: hidden; }
  #aboutus_submenu {  left: 306px; visibility: hidden; }
  #contact_submenu { left: 408px; visibility: hidden; }
  /* Note, each submenu is hidden when the page loads - then made visible when
      the mouse goes over the menu title. Using the 'visibility' property instead
      of using the 'display' property avoided a bug in some versions of Safari.
      (The bug is pretty where esoteric: The browser ignored the 'hover' property
      on 'li' objects inside an object whose display property was set to 'none'
      when the page loaded...) Using the 'visibility' property instead of 'display'
      would normaly take up extra room on the page, but that's avoided here by putting
      the submenu on a second layer: see 'position: absolute' and 'z-index: 2'
      in .submenu definition, higher up this page. */
  
  .submenu a
  {
    display: block;
    color: #eee;
    background-color: #666633;
    width: 146px; /* This should be width of .submenu above minus right-side padding on next line */
    padding: 5px 0px 4px 20px;
    text-decoration: none;
    background-color: #666633;
    border-bottom: #447755 dotted 1px;
    border-top: 0; border-left: 0; border-right: 0;
  }
  
  
  ul { position: relative; display: block; }
  li { position: relative; display: block; }
  
  .submenubox {
    margin: 0; padding: 0; border: 0;
  }
  .submenubox ul
  {
    margin: 0; padding: 0; border: 0;
    list-style-type: none;
  }
  
  .submenubox ul li {
    margin: 0; padding: 0; border: 0;
  }
  
  .submenubox ul li a:link { }
  .submenubox ul li a:visited { }
  .submenubox ul li a:hover
  {
    color: #c6e8e2; /* text color for submenu items */
    background-color: #447755;
    border-bottom: #447755 dotted 1px;
  }
  
  
  &lt;/style&gt;
  &lt;script type="text/javascript"&gt;
  // JavaScript functions to show and hide drop-down menus.
  // In SimpleNavBar.html we call ShowMenuDiv each time the mouse goes over
  // either the menu title or the submenu itself, and call HideMenuDiv when the
  // mouse goes out of the menu title or the submenu iteslf (onMouseOut).
  
  function ShowItem (itemID) {
    var x = document.getElementById(itemID);
    if (x)
      x.style.visibility = "visible";
    return true;
  }
  
  function HideItem (itemID) {
    var x = document.getElementById(itemID);
    if (x)
       x.style.visibility = "hidden";
    return true;
  }
  
  //    As noted in the SimpleNavBarStyles.css file, using x.style.visibility as
  //    seen below seemed to have better cross browser support than using
  //    x.style.display="block" and x.style.display="none" to show and hide
  //    the menu.
  &lt;/script&gt;
  &lt;div class="mynavbar"&gt;
  
  &lt;a onmouseover="ShowItem('products_submenu');" onmouseout="HideItem('products_submenu');" href="placeholder.html" id="t1" class="navbartitle"&gt;Products&lt;/a&gt;&lt;a onmouseover="ShowItem('services_submenu');" onmouseout="HideItem('services_submenu');" href="placeholder.html" id="t2" class="navbartitle"&gt;Services&lt;/a&gt;&lt;a onmouseover="ShowItem('funstuff_submenu');" onmouseout="HideItem('funstuff_submenu');" href="placeholder.html" id="t3" class="navbartitle"&gt;Fun Stuff&lt;/a&gt;&lt;a onmouseover="ShowItem('aboutus_submenu');" onmouseout="HideItem('aboutus_submenu');" href="placeholder.html" id="t4" class="navbartitle"&gt;About Us&lt;/a&gt;&lt;a onmouseover="ShowItem('contact_submenu', 't5');" onmouseout="HideItem('contact_submenu');" href="placeholder.html" id="t5" class="navbartitle"&gt;Contacts &amp;amp; Directions&lt;/a&gt;
  
  
  &lt;!-- REPLACE each "placeholder.html" URL below with the specific page you want
        the user to go to when the given submenu item is clicked.  --&gt;
  
  &lt;!-- Products sub-menu, shown as needed  --&gt;
  &lt;div onmouseout="HideItem('products_submenu');" onmouseover="ShowItem('products_submenu');" id="products_submenu" class="submenu" style="visibility: hidden;"&gt;
    &lt;div class="submenubox"&gt;
      &lt;ul&gt;
        &lt;li&gt;&lt;a class="submenlink" href="placeholder.html"&gt;Flying Cars&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a class="submenlink" href="placeholder.html"&gt;Super Squirters&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a class="submenlink" href="placeholder.html"&gt;Sling Shots&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a class="submenlink" href="placeholder.html"&gt;Bamboozlers&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a class="submenlink" href="placeholder.html"&gt;Kazoos&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/div&gt;
  
  &lt;/div&gt;
  
  &lt;!-- Services sub-menu, shown as needed  --&gt;
  &lt;div onmouseout="HideItem('services_submenu');" onmouseover="ShowItem('services_submenu');" id="services_submenu" class="submenu"&gt;
    &lt;div class="submenubox"&gt;
      &lt;ul&gt;
        &lt;li&gt;&lt;a class="submenlink" href="placeholder.html"&gt;Toy Design&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a class="submenlink" href="placeholder.html"&gt;Market Research&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a class="submenlink" href="placeholder.html"&gt;IP Consulting&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a class="submenlink" href="placeholder.html"&gt;Licensing&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;&lt;/div&gt;
  &lt;/div&gt;
  
  &lt;!-- Fun Stuff sub-menu, shown as needed  --&gt;
  &lt;div onmouseout="HideItem('funstuff_submenu');" onmouseover="ShowItem('funstuff_submenu');" id="funstuff_submenu" class="submenu" style="visibility: hidden;"&gt;
    &lt;div class="submenubox"&gt;
      &lt;ul&gt;
        &lt;li&gt;&lt;a class="submenlink" href="placeholder.html"&gt;Toys We Designed&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a class="submenlink" href="placeholder.html"&gt;Press Ravings&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a class="submenlink" href="placeholder.html"&gt;Our Blog&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;!-- About Us sub-menu, shown as needed  --&gt;
  &lt;div onmouseout="HideItem('aboutus_submenu');" onmouseover="ShowItem('aboutus_submenu');" id="aboutus_submenu" class="submenu" style="visibility: hidden;"&gt;
    &lt;div class="submenubox"&gt;
      &lt;ul&gt;
        &lt;li&gt;&lt;a class="submenlink" href="placeholder.html"&gt;Team&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a class="submenlink" href="placeholder.html"&gt;Investors&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a class="submenlink" href="placeholder.html"&gt;Partners&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a class="submenlink" href="placeholder.html"&gt;Careers&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a class="submenlink" href="placeholder.html"&gt;Our Blog&lt;/a&gt;&lt;/li&gt;
       &lt;/ul&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;!-- CONTACTS &amp; DIRECTIONS sub-menu, shown as needed  --&gt;
  &lt;div onmouseout="HideItem('contact_submenu');" onmouseover="ShowItem('contact_submenu');" id="contact_submenu" class="submenu" style="visibility: hidden;"&gt;
    &lt;div class="submenubox"&gt;
      &lt;ul&gt;
        &lt;li&gt;&lt;a class="submenlink" href="placeholder.html"&gt;Contact&lt;/a&gt;&lt;/li&gt;
         &lt;li&gt;&lt;a class="submenlink" href="placeholder.html"&gt;Getting Here&lt;/a&gt;&lt;/li&gt;
     &lt;/ul&gt;
    &lt;/div&gt;
  &lt;/div&gt;&lt;!-- end of sub-meus --&gt;
  
  &lt;/div&gt;
  
  &lt;div&gt;&lt;select  style="margin-left: 200px; position: relative; z-index: 0;"&gt;
                  &lt;option value=""&gt;&lt;/option&gt;
                  &lt;option value="28"&gt;Test&lt;/option&gt;
                  &lt;option value="Eff2"&gt;Test&lt;/option&gt;
                  &lt;option value="Effort1"&gt;Test&lt;/option&gt;
                  &lt;option value="FC"&gt;Test&lt;/option&gt;
                  &lt;option value="Effort1"&gt;Test&lt;/option&gt;&lt;option value="Effort1"&gt;Test&lt;/option&gt;&lt;option value="Effort1"&gt;Test&lt;/option&gt;&lt;option value="Effort1"&gt;Test&lt;/option&gt;
  
              &lt;/select&gt;
              &lt;/div&gt;
  </code></pre>