0

我有一个输入字段,用作我的网络应用程序的搜索栏。当用户开始使用 JQuery 输入时,会出现一个#search-suggestions div,并使用 AJAX 填充建议。现在,我为我的 JSFIDDLE 取出了 JQUERY 和 AJAX,但通常 div 在您开始输入之前是隐藏的(例如,我只是让它可见)。如何将#search-suggestions div 直接放在输入下方?什么是正确的 css?

JSFIDDLE:http: //jsfiddle.net/nFEnz/

CSS:

#search-suggestions {
padding: 0px 0px 10px 0px;
height: auto;
width: 298px;
border: 1px solid #ddd;
border-radius: 4px 4px 4px 4px;
background-color: #fff;
}

谢谢!

4

2 回答 2

0

尝试这个。 http://jsfiddle.net/nFEnz/9/

#search {
    float: left;
    margin: 0px 0px 0px 0px;
    padding: 0px 0px 0px 0px;
    height: 28px;
    width: 293px;
    border: 1px solid #ddd;
    border-radius: 4px 4px 4px 4px;
    -webkit-box-shadow: #EEE 0px 2px 6px 0px inset;
    background-color: #fff;
    position:relative;
}

#search input {
    float: left;
    outline: none;
    height: 28px;
    width: 265px;
    border: none;
    background: transparent;
    font-family: calibri;
    font-size: 16px;
    color: #777;
}

#search-icon {
    cursor: pointer;
    float: left;    
    height: 28px;
    width: 28px;
    border: none;
    background: transparent;
}

#search-icon img {
    height: 20px;
    width: 20px;
}

#search-suggestions {
    padding: 0px 0px 10px 0px;
    height: auto;
    width: 298px;
    border: 1px solid #ddd;
    border-radius: 4px 4px 4px 4px;
    background-color: #fff;
    position:absolute;
    top:31px;
}

#loading-suggestions {
    margin-top: 10px;
    margin-left: auto;
    margin-right: auto;
    height: 40px;
    width: 40px;
}

#loading-suggestions img {
    height: 40px;
    width: 40px;
}

.search-suggestion {
    padding: 5px 10px 5px 10px;
    height: auto;
    width: 278px;
    overflow: auto;
}

.search-suggestion:last-child {
    padding: 5px 10px 0px 10px;
}

.search-suggestion-picture {
    float: left;
    height: 50px;
    width: 50px;
    border: 1px solid #ddd;
    border-radius: 4px 4px 4px 4px;
    overflow: hidden;
}

.search-suggestion-picture img {
    height: auto;
    min-height: 50px;
    width: 50px;
}

.search-suggestion-stuff {
    float: left;
    margin: 0px 0px 0px 10px;
    height: 50px;
    width: 200px;
}

.search-suggestion-name {
    height: 50px;
    width: auto;
}

.search-suggestion a {
    text-decoration: none;
    margin: 0px 0px 5px 0px;
    padding: 0px 0px 0px 0px;
    font-family: calibri;
    font-weight: bold;
    font-size: 16px;
    color: #444;
    line-height: 50px;
}

.search-suggestion a:hover {
    text-decoration: underline;
}
于 2013-07-09T17:25:17.780 回答
0

使#searchto beposition:relative和 the #search-suggestionsto beposition:absolute并拥有一个top:100%.

#search {
    ... /*your current styles*/

    position:relative; /*ADDED THIS LINE*/
}

#search-suggestions {
    ... /*your current styles*/

    position:absolute; /*ADDED THIS LINE*/
    top:100%; /*ADDED THIS LINE*/
    left:0; /*ADDED THIS LINE*/
}

演示在 http://jsfiddle.net/nFEnz/7/

于 2013-07-09T17:28:59.087 回答