AJAX自动完成文本框的动态高度。

时间:2021-11-12 03:18:13

I am using the AJAX autocomplete add-on to the <asp:textbox> control. I have everything working with a <div> around the <ajaxToolkit:AutoCompleteExtender>.

我正在使用AJAX autocomplete附加到 控件。我在 周围使用

I set the following CSS class:

我设置了以下CSS类:

.autocomplete_CompletionListElement
{
    margin: 0px;
    background-color: White;
    cursor: default;
    overflow-y: auto;
    overflow-x: hidden;
    height:180px;
    text-align: left;
    border: 1px solid #777;
    z-index:10000;
}

Right now, when the list contains a reasonable amount of items, a vertical scrollbar appears (which is correct) and I can scroll through the drop down which is set to a height of 180px in the CSS (as seen above).

现在,当列表包含合理数量的项目时,会出现一个垂直滚动条(这是正确的),我可以向下滚动,它在CSS中被设置为180px的高度(如上所示)。

However, when there are only 1 or 2 items in the drop down, the height remains fixed at 180px with the 2 items and blank white space below. What I would ideally want is that the AJAX drop down would shrink to fit the height of its contents. If the contents are more than 180px, then the scrollbar should appear (as it is doing now).

但是,当下拉框中只有1或2个项目时,高度保持在180px,下方为2个项目和空格。理想情况下,我想要的是,AJAX下拉将缩小以适应其内容的高度。如果内容大于180px,那么滚动条应该会出现(就像现在这样)。

1 个解决方案

#1


3  

Remove height:180px and change the CSS to use something like:

删除高度:180px,将CSS更改为以下内容:

max-height:180px;

That should work (but I think only from IE7+) the other browsers should support it ok.

这应该是可行的(但我认为只有IE7+)其他浏览器应该支持它。

#1


3  

Remove height:180px and change the CSS to use something like:

删除高度:180px,将CSS更改为以下内容:

max-height:180px;

That should work (but I think only from IE7+) the other browsers should support it ok.

这应该是可行的(但我认为只有IE7+)其他浏览器应该支持它。