在我的 webapp 中,我在网页顶部的固定工具栏中有一个搜索框。我像这样实现了工具栏的固定位置....
#toolbar {
position: fixed !important;
position: absolute;
height: 25px;
width: 100%;
top: 0px;
left: 0px;
margin: 0;
z-index: 100;
font-size: 12px;
}
现在,我正在使用jQuery 插件在其上实现关键字自动完成功能。
我的问题是如何在窗口滚动/调整大小时保持自动完成建议固定/附加到搜索框。
自动完成建议框的 css 是....
element.style {
display:none;
left:166px;
position:absolute;
top:96px;
width:130px;
}
.ac_results {
background-color:white;
border:1px solid #C5DBEC;
overflow:hidden;
padding:0;
z-index:99999;
}
我执行这些操作时遇到问题..
- 在搜索框中输入内容,导致出现建议
- 打开搜索框,我滚动窗口。
- 这会导致自动建议框也被滚动。
我能做些什么来解决这个错误?
这是它的外观。
自动完成已滚动到固定位置的输入框。
更新1:我尝试添加position: fixed;
到自动完成。
这在不同的情况下会出现问题。
- 在搜索框中输入内容,导致出现建议
- 按退出键,导致框消失
- 向下滚动窗口
- 在搜索框中输入内容,导致出现建议
- 现在搜索框出现在滚动前出现的位置,因为位置是固定的
更新:
更新 2:
添加到自动完成 css 的以下代码可以解决问题。
.ac_results {
background-color:white;
border:1px solid #C5DBEC;
overflow:hidden;
padding:0;
z-index:99999;
position: fixed;
top: 0px;
margin: 20px 0px 0px 0px; /* The top margin defines the offset of textbox */
}
问候