简体   繁体   English

菜单,在Bootstrap导航栏上的搜索栏下...不兼容

[英]Menu, under search bar on nav-bar in Bootstrap…not compatible

I am trying to create a search bar with results that appear right under the bar, but I am faced with a number of problems while trying to implement this. 我正在尝试创建一个搜索栏,其结果显示在栏下方,但我在尝试实现此问题时遇到了许多问题。 I am new in web programming, which is why I prefer to use bootstrap because of its compatibility on different screen sizes. 我是网络编程的新手,这就是为什么我更喜欢使用bootstrap,因为它兼容不同的屏幕尺寸。 In this case, I don't know which method to use and I simply created "div" under the bar, but I am not sure if it is the correct way. 在这种情况下,我不知道使用哪种方法,我只是在栏下创建“div”,但我不确定它是否是正确的方法。 Would be happy if you gave me suggestion. 如果你给我建议,会很高兴。

Below I included the code with css that I used. 下面我包含了我用过的css代码。 I gave hard-coded value for the width as 174px, while I need something that automatically identifies the width of search bar and sets that value as maximum. 我给出了宽度为174px的硬编码值,而我需要一些能自动识别搜索栏宽度并将该值设置为最大值的东西。 ID="searchResults" is the string that I get in real time using jQuery and Ajax. ID="searchResults"是我使用jQuery和Ajax实时获得的字符串。

Would be happy if you give me advice about the way how to implement this. 如果你给我关于如何实现这个的方法的建议,会很高兴。

 <div class="navbar-form navbar-left">
       <input class="form-control" placeholder="Search..." type="text"
       autocomplete = off  id = "autocomplete_search">
      <div  id="searchResults" 
            style="position: absolute;
                width: 174px;
                background: white;
                border-bottom-left-radius: 10px;
                border-bottom-right-radius: 10px;
                max-height: 200px;
                overflow-y: auto;
                margin-top: -3px;"> </div>
 </div>

your attemp is ok. 你的尝试还可以。 .navbar-form navbar-left needs to be position: relative; .navbar-form navbar-left需要是position: relative; . If you do that, you can use this element to position and size the absolute container of #searchResults . 如果这样做,您可以使用此元素来定位和#searchResults的绝对容器。

Your HTML is not valid, here is a more clean version: 您的HTML无效,这是一个更干净的版本:

<div class="navbar-form navbar-left">
    <input class="form-control" placeholder="Search..." type="text" autocomplete="off"  id="autocomplete_search" />
    <div id="searchResults">So much results...</div>
 </div>

Here is some CSS to put the html in shape: 这是一些将html放入形状的CSS:

.navbar-form
{
    position: relative;

    /* just a little demo */
    margin-left:200px;
}

.form-control
{
    width: 100%;
}

#searchResults
{
    position: absolute;
    width: auto; 
    background: white;
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
    max-height: 200px;
    overflow-y: auto;

    border: 1px solid gray;

    /*This is relative to the navbar now*/
    left: 0;
    right: 0;
    top: 20px;
}

And here is a little demo: http://jsfiddle.net/NicoO/ZAyN9/ 这是一个小小的演示: http//jsfiddle.net/NicoO/ZAyN9/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM