【问题标题】:Z-index in jQuery dialog. Autosuggest list not displayed properlyjQuery 对话框中的 Z-index。自动建议列表未正确显示
【发布时间】:2011-08-07 07:04:47
【问题描述】:

在 jQuery 对话框中显示自动建议框时出现问题。无论如何,自动建议列表都会显示在对话框下方。我尝试将 autosuggest 的 z-index 属性设置为 > 1004。但没有运气。

下面是截图。

这是我用来设置自动建议列表样式的 CSS 类:

ul.as-list {
    position: absolute;
    list-style-type: none;
    margin: 2px 0 0 0;
    padding: 0;
    font-size: 14px;
    color: #000;
    font-family: "Lucida Grande", arial, sans-serif;
    background-color: #fff;
    background-color: rgba(255,255,255,0.95);
    box-shadow: 0 2px 12px #222;
    -webkit-box-shadow: 0 2px 12px #222;
    -moz-box-shadow: 0 2px 12px #222;
    border-radius: 5px;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    z-index:6000;
}

li.as-result-item, li.as-message {
    margin: 0 0 0 0;
    padding: 5px 12px;
    background-color: transparent;
    border: 1px solid #fff;
    border-bottom: 1px solid #ddd;
    cursor: pointer;
    border-radius: 5px;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    z-index:6000;
}

我已经在这个jsfiddle 页面上传了完整的代码。你可以清楚地看到那里的问题。我该如何解决?

【问题讨论】:

    标签: javascript css jquery-ui dialog z-index


    【解决方案1】:

    根本原因是最外面的两个元素有overflow: hidden

    解决这个问题的最简单方法是:

    .ui-dialog, .ui-dialog-content {
        overflow: visible !important
    }
    

    如果您对使用!important 不满意(这不是一个好的做法),您可以找到实际应用overflow: hidden 的地方,并在那里修复它。

    快速修复版本:http://jsfiddle.net/mNQVr/在 Chrome、Firefox、IE 中测试

    【讨论】:

      【解决方案2】:

      这是你可以做的:

      $("#txtTagAdd").autoSuggest(data.items, {
                              asHtmlID:"tagg",
                              selectedItemProp: "name",
                              searchObjProps: "name",
                              selectionLimit:4,
                              limitText: "Only 4 tags unique tags allowed for each suggestion",
                   resultsComplete: function(){
                       var h = $('ul.as-list').innerHeight() + 20;
                       $('div.as-results').css({"height": h + "px"});
                   }
      });
      

      【讨论】:

      • 这也扩展了 jquery 对话框.. :(
      【解决方案3】:

      这可以做到:

      ul.as-list {
          position: fixed;
          /*...*/
      }
      

      【讨论】:

        【解决方案4】:

        它应该可以工作,因为我在您提供的 jsfiddle 链接中进行了测试:

        div.as-results{position:relative;z-index:1;}
        div.as-results ul.as-list {
            position: fixed;
            list-style-type: none;
            margin: 2px 0 0 0;
            padding: 0;
            font-size: 14px;
            color: #000;
            font-family: "Lucida Grande", arial, sans-serif;
            background-color: #fff;
            background-color: rgba(255,255,255,0.95);
            box-shadow: 0 2px 12px #222;
            -webkit-box-shadow: 0 2px 12px #222;
            -moz-box-shadow: 0 2px 12px #222;
            border-radius: 5px;
            -webkit-border-radius: 5px;
            -moz-border-radius: 5px;
            z-index:6000;
        }
        

        【讨论】:

        • @naveed,您正在使用哪个浏览器...应用上述样式后,我仍然遇到同样的问题。可能您可以保存您的 jsfiddle 版本并分享链接。我会调查的
        • @Ramesh Vel:嗯,看起来像我编辑的小提琴,使用位置:固定,真的。 jsfiddle.net/fTYsC/2
        • @naveed,您的代码在 chrome 中按预期工作,而不是在 Firefox 中。我刚刚验证了
        • @Ramesh Ve,我使用的是 Chrome,让我检查一下其他解决方案,但我知道 position: fixed 并非所有浏览器都支持。
        • @Naveed afaik position:fixed受 IE6 支持(也许是 7,不确定)并且受所有其他浏览器支持。
        猜你喜欢
        • 2016-05-17
        • 2011-03-14
        • 2012-11-15
        • 1970-01-01
        • 1970-01-01
        • 2013-02-11
        • 1970-01-01
        • 2014-08-22
        • 1970-01-01
        相关资源
        最近更新 更多