IE z-index relative/absolute bug in list

后端 未结 8 1848
迷失自我
迷失自我 2020-12-31 08:12

I have the following navigation where .topNav has position:relative and subnav has position:absolute. I cant get the sublist to appear over the main list due to z-index prob

相关标签:
8条回答
  • 2020-12-31 08:42

    I had the same issue and was able to fix it In IE6 and 7. Combining http://code.google.com/p/ie7-js/ with the following CSS the issue went away. With my issue I had some items inside a list floated left and had a tooltip that popped up whenever the user hovered over the li. To fix it, I adde this:

    .ul li:hover {position:relative;z-index:4;} .ul li:hover + li {position:relative;z-index:3;}

    The way it works is whenever the user hovers over the first LI for example, it sets the second LI floated next to it to a lower z-index value. You can of course change the z-index values to fit your own needs.

    0 讨论(0)
  • 2020-12-31 08:52

    adding

    background: url(blank.gif); 
    

    for absolutely positioned elemnts solves the problem for me. Mybe it can helps u 2 :)

    regards

    0 讨论(0)
  • 2020-12-31 08:54

    Here's a very good article that explains the stacking issues that machineghost mentions.

    http://css-discuss.incutio.com/wiki/Overlapping_And_ZIndex

    What you might want to consider (depending on why you're wanting the positioning on multiple elements) is adding a hover selector to .base (use JavaScript for IE6) that adds the class to give it relativity.

    .base:hover{position:relative;}
    

    This then means that the second .base doesn't have position: relative.

    0 讨论(0)
  • 2020-12-31 08:55

    Ok, I think your problem probably stems from a lack of understanding about how z-index works. The z-index property is only relevant for elements at the same level in the DOM hierarchy. In other words, if you have:

    <ul id="a">
      <li id="b">b</li>
      <li id="c">c</li>
    </ul>
    <div id="d"></div> 
    

    and "b" and "c" are styled such that they overlap, z-index will determine which one ends up on top. However, if "c" and "d" overlap, "d" will always be on top, no matter what c's z-index is, because elements that are closer to the root DOM node will always appear above elements that are nested deeper in.

    So, as long as "subnNav" is a child of "topNav," I don't think there is any way to make it cover it's parent's content. In other words, as far as I know there is no workaround for this issue, except to make "subNav" not be a child of "topNav".

    (NOTE: All that being said, CSS is not simple, so there may still be some way to get the effect you want that I'm not aware of. All I can say is that, based on my understanding of z-index and my pretty good general CSS knowledge, there's no way that I know of.)

    0 讨论(0)
  • 2020-12-31 08:56

    Stu Nicholls at CSSplay has a get CSS Based nav w/ 6 level drop down (Can be expanded to more if needed). This works in Internet Explorer IE5.5, IE6, IE7, Firefox, Opera and now Safari, Netscape 8 and Mozilla.

    0 讨论(0)
  • 2020-12-31 08:59

    Solution: assign z-index in decreasing order

    <div class="base" style="z-index:2">
    <div class="inside">
        This has some more text in it. This also has a background. This should obscure the second block of text since it has a higher z-index.
    </div>
    This has some text in it. This has some text in it. This has some text in it. This has some text in it. This has some text in it.
    </div>
    
    <div class="base" style="z-index:1">
    This is the second div. You should not be seeing this in front of the grey box. This has some text in it. This has some text in it. This has some text in it. This has some text in it. This has some text in it. This second box should be obscured by the grey box.
    </div>
    
    0 讨论(0)
提交回复
热议问题