【发布时间】:2014-06-02 19:46:51
【问题描述】:
我在我们的网站上使用 jQuery 自动完成功能,它工作正常,除了偶尔无法看到自动完成返回的某些行,它们几乎隐藏在它所在的 div 中。
什么是最简单/最好的解决方案来实现这一点,以便它可以显示所有行并与包含的 div 重叠。
我的 CSS
.autocomplete-suggestions {
background-color: #79BE28;
border-radius: 7px;
box-shadow: 0 4px 4px #CCCCCC;
max-height: 650px !important;
width: 520px !important;
}
.autocomplete-suggestions .autocomplete-suggestion {
font-size: 12px;
text-align: left;
color: #fff;
padding: 4px 15px;
cursor: pointer;
}
.autocomplete-suggestions .autocomplete-suggestion:hover {
font-weight: bold;
}
.autocomplete-suggestions .autocomplete-suggestion strong {
text-decoration: underline;
}
.autocomplete-suggestion {
z-index: -1 !important;
}
HTML
<div id="appendTo">
<div class="autocomplete-suggestions" style="position: absolute; max-height: 300px; z-index: 9999; width: 269px; display: block;">
<div data-index="0" class="autocomplete-suggestion"><strong>Sain</strong>t Ives Nursery, 15 Needingworth Road, St. Ives, Cambridgeshire, PE275JP, United Kingdom</div>
<div data-index="1" class="autocomplete-suggestion"><strong>Sain</strong>t Thomas More Catholic Primary School, Marsland Road Hesters Way, Cheltenham, , GL510HX, United Kingdom</div>
<div data-index="2" class="autocomplete-suggestion"><strong>Sain</strong>t James' Primary School, Moorgreen Road, West End, Southampton, Hampshire, SO303EG, United Kingdom</div>
<div data-index="3" class="autocomplete-suggestion"><strong>Sain</strong>t Pius X Catholic High School, Wath Wood Road, Wath upon Dearne, Rotherham, South Yorkshire, S637PQ, United Kingdom</div>
<div data-index="4" class="autocomplete-suggestion"><strong>Sain</strong>t Benedict Catholic School, Duffield Road, Darley Abbey, Derby, Derbyshire, DE221JD, United Kingdom</div><div data-index="5" class="autocomplete-suggestion"><strong>Sain</strong>t Cecilia's Wandsworth CofE School, Sutherland Grove, London, Greater London, SW185JR, United Kingdom</div>
<div data-index="6" class="autocomplete-suggestion"><strong>Sain</strong>tfield High School, 21 Comber Road, <strong>Sain</strong>tfield, Ballynahinch, County Down, BT247BB, United Kingdom</div>
<div data-index="7" class="autocomplete-suggestion">My school is not listed</div></div>
<div class="autocomplete-suggestions" style="position: absolute; display: none; max-height: 300px; z-index: 9999;"></div>
【问题讨论】:
-
你可以给结果容器
overflow-y:auto! -
@DhavalMarthak 随意给我这个答案,我也接受
-
你能用jsfiddle.net创建一个演示吗?
标签: jquery css autocomplete client-side