views:

824

answers:

2

Hi,

I am using the AJAX autocomplete add-on to the control. I have everything working with a around the .

I set the following CSS class:

.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).

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).

I would greatly appreciate any help in this issue.

Thanks, Tim

+1  A: 

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

max-height:180px;

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

jitter
Thanks! What would the effect of max-height be on browsers which do not support it? Will the height be fixed at 180 just the same in the worst case?
TMM
Well for this to work you have to remove height:180px so if max-height is not supported the list will autofit itself and no vertical scrollbars should appear. Autofit to whatever height is required, so if the list is long you are in troubleSo I guess the best idea will be to use a browser hack (conditional comment) for IE < IE7 set fixed height 180px for all others use max-height
jitter
Maybe this would work for all browsers: height: expression (this.scrollHeight > 179 ? "180px" : "auto" ); /* sets max-height for IE */ max-height: 180px; /* sets max-height value for all standards-compliant browsers */ as suggested here:http://perishablepress.com/press/2007/01/16/maximum-and-minimum-height-and-width-in-internet-explorer/Thanks
TMM
This works. But this violates css compliance if you care about that. While the conditional comment solution is ok as the cond. comm. are normal comments for all other browsers.Don't forget to upvote me for all the work if you want :p
jitter
A: 

Genio!! Funciono

carina