z-index not working on drop down menu

12,999

Solution 1

I think I have found the issue. I was using opacity on the div containing the menu. For some reason this caused z-index to not work on the sub-menu. I am not sure why this is. It works fine now that I've removed the opacity rule.

Solution 2

Check the z-index of the elements it is supposed to appear above. make sure they are lower. Also make sure that the parent element hasn't got the overflow hidden.

Share:
12,999
Luke Vella
Author by

Luke Vella

Updated on June 07, 2022

Comments

  • Luke Vella
    Luke Vella almost 2 years

    I have a drop down menu which has the following html structure:

    <ul class="menu">
       <li><a href="">Menu Item 1</a>
          <ul class="sub-menu">
             <li><a href="">Sub Menu Item 1</a></li>
          </ul>
       </li>
    </ul> 
    

    and I have the following css rules:

    .menu {float:left}
    .menu > li {position:relative; float:left}
    .menu > li > a {display:block}
    .sub-menu {display:none; z-index:100; position:absolute; top:40px; width:180px;}
    

    I'm using javascript to show the drop down menu.

    The issue I have is that the sub-menus are appearing below a slideshow which I have close to the navigation. No matter how high or how low I set the z-index of .sub-menu, nothing changes.

    Does anyone know what could possibly trigger z-index to not work at all?

    Thanks.

    EDIT: The issue is with all browsers. Testing in Firefox, Chrome and Internet Explorer

    • devdavid
      devdavid about 13 years
      Does this problem occur only in a specific browser?
    • thirtydot
      thirtydot about 13 years
      Make a jsFiddle test case, or even better provide a live link to the afflicted page.
    • Luke Vella
      Luke Vella about 13 years
      The issue occurs in all browsers, I'll add this detail to the main post.
    • Capagris
      Capagris almost 12 years
      if you solved your own issue, 'post your answer' independently and select is as the correct answer
  • Luke Vella
    Luke Vella about 13 years
    I tried that and it doesn't seem to work. Changing the z-index of .menu > li does have an effect on .menu > li but not on .sub-menu
  • Robin Maben
    Robin Maben about 13 years
    Also note, the z-index is applied for an element contained within one having relative positioning. As correctly shown above.
  • DelPiero
    DelPiero about 11 years
    Wow, had to dig around a bit to find this. Been trying to solve this issue as well, thank you VERY much! How strange that specifying an opacity on the div containing the menu causes this problem...