jquery - Chrome 中相对定位的 div 上的绝对定位元素

标签 jquery html css css-position

我发现 Chrome 在相对定位的 div 上显示绝对定位元素的方式不同

这是一些标记:

<div id="maincontent">
<table id="mainTable">
   <tr class="menuRow">
       <td >
            <div id="menu">
                <ul id="panel">
                    <li>Option 1</li>                                     
                    <li>Option 2</li>                                     
                    <li>Option 3</li>                                     
                </ul>    
            </div>
     </td>
    </tr>
    <tr>
        <td class="contentRow">
            <div id="content" >

            </div>
       </td>
    </tr>
</table>

CSS:

#maincontent { width: 100%; }
#mainTable { width: 100%; }
#menu { position: fixed; background-color: green; 
width: 30px; height: 30px; cursor:     pointer; }
#panel{ position: absolute; height: 150px; width: 100px;
 background-color: red;     display:none; z-index:10; }
#content { margin-top: 30px; height: 300px; width:300px;
 background-color: #00F; position:relative;}​

我整理了一个样本 here这表明我的问题。 (如果将鼠标移到绿色框上,则会显示红色“菜单”)

在 IE 和 Firefox 中,我可以在蓝色内容上正确地看到它。在 Chrome 中,“菜单”显示在内容后面。有什么方法可以使它适用于 Chrome?

非常感谢,欢迎任何反馈。

最佳答案

是的,在 #menu 上调高 z-index:

#menu { 
    position: fixed; 
    background-color: green; 
    width: 30px; 
    height: 30px; 
    cursor: pointer; 
    z-index: 9999;
 }

http://jsfiddle.net/Ezn4v/

关于jquery - Chrome 中相对定位的 div 上的绝对定位元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13055052/

相关文章:

javascript - 立即取消选中所有 JQuery 单选按钮集

html - Bootstrap 图标是蓝色而不是白色,而且垂直位置不佳

html - 辅助功能:使用媒体查询隐藏文本

javascript - 为什么 deferred.when() 在完成回调中返回 promise ?

javascript - 如何在 aspnet webforms 中使用 ajax 根据另一个下拉列表选择的值绑定(bind)下拉列表

java - 如何使用Java在html表中创建行

php - HTML 表单、php 和撇号

jquery - 将 fullPage.js 添加到 Foundation

html - 彩色变音符号和 unicode 行为

javascript - 为什么 jQuery 的 event.which 在 Firefox 和 Chrome 中给出不同的结果?