2

I have the following button with associated context menu

    <div class="control-action"> 
        <button>Action</button> 
        <ul style="display:none">
            <li class="action-remove">Remove</li>
            <li class="action-detail">Detail</li>
            <li class="action-assigned">Assign</li>
        </ul>
    </div> 

When the button is clicked the associated ul shows beneath it as a context menu.

This is working great on all browsers except IE 7. In IE7 the context menu (ul) shows beneath the button below it. I imagine this is likely due to how the stacking context is resolving these elements.

My css currently looks like this:

.control-action
{
    position: relative;
    text-align:right;
    width:100px;    
}

.control-action ul
{
    position:absolute;
    z-index: 10000;
    list-style:none;
}

Any ideas as to what I'm doing wrong?

Kara
  • 6,115
  • 16
  • 50
  • 57
cweston
  • 11,297
  • 19
  • 82
  • 107

4 Answers4

2

IE up to IE7 uses the nearest positioned ancestor to determine the stacking context. You seeing that in IE6 too?

Put your button after the ul and then try it.

albert
  • 8,112
  • 3
  • 47
  • 63
2

IE7 has known bugs with z-index.

Without seeing your full page, the best I can do is point you to some resources which explain the issue:

The idea, in its most basic form, is to test adding/removing position: relative and z-index on parents of the problematic element until it's fixed.

Community
  • 1
  • 1
thirtydot
  • 224,678
  • 48
  • 389
  • 349
2

I have resolved this by changing the element ordering. I have removed the relative position element from containing both my button and menu, and made it only the parent of menu.

    <div class="control-action" style="float:right"> 
        <div class="control-action-menu">
            <ul style="display:none">
                <li class="action-remove">Remove</li>
                <li class="action-detail">Detail</li>
                <li class="action-assigned">Assign</li>
            </ul>
        </div>
        <button>Action</button> 
    </div> 

With this markup change the css has changed into the following:

.control-action
{
    text-align:right;
    width:100px;    
}

.control-action-menu
{
    position:relative;
    z-index:1;
}

.control-action ul
{
    position:absolute;
    z-index: 10000;
    list-style:none;
}
thirtydot
  • 224,678
  • 48
  • 389
  • 349
cweston
  • 11,297
  • 19
  • 82
  • 107
  • 2
    You might want to fix `contol` to `control`. Also, if you ever post another question about IE7 z-index woes, please include a complete test page. It will make the question *far easier* to precisely answer. Anyway, I'm glad you got it sorted. – thirtydot Jun 03 '11 at 16:43
0

Could be the hasLayout bug.

This may help: IE7 relative/absolute positioning bug with dynamically modified page content

Community
  • 1
  • 1
Jason Gennaro
  • 34,535
  • 8
  • 65
  • 86