Z-index in jQuery dialog. Autosuggest list not displayed properly

时间秒杀一切 提交于 2019-12-30 11:00:19

问题


I have a problem displaying the autosuggest box inside a jQuery dialog. The auto suggest list is displayed under the dialog no matter what. I have tried setting up the z-index property of autosuggest to > 1004. But no luck.

Below is the screenshot.

This is the CSS class I have used to style the autosuggest list:

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;
}

I have uploaded the complete code in this jsfiddle page. You can see the problem there clearly. How can I fix it?


回答1:


The root cause is that the outermost two elements have overflow: hidden.

The simplest way to fix that is:

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

If you're not happy with using !important (it's not good practise), you can find the place where overflow: hidden is actually being applied, and fix it there.

Quick fix version: http://jsfiddle.net/mNQVr/ (tested in Chrome, Firefox, IE)




回答2:


This is what you can do:

$("#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"});
             }
});



回答3:


This may do it:

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



回答4:


It should work as I tested that in jsfiddle link you provided:

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;
}


来源:https://stackoverflow.com/questions/5693388/z-index-in-jquery-dialog-autosuggest-list-not-displayed-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!