Bootstrap导航栏顶部固定搜索输入内容与页面滚动

时间:2015-11-11 20:17:16

标签: html css twitter-bootstrap autocomplete

为了冥想Bootsrap固定导航栏中包含的Google地图自动填充功能(顶部)我有这个:

  <nav class="navbar navbar-fixed-top">
    <div class="container">
        <div class="navbar-header navbar-collapse navbar-responsive-collapse collapse">
            <a href="/" class="navbar-brand"><img src="" height="40"></a>
        </div>

        <div id="search-container" class="col-md-6 col-md-offset-1 col-sm-5 col-sm-offset-1">
            <div class="row">
                    <div class="input-group">
                        <input name="searchbar" id="searchbar" class="form-control ui-autocomplete-input" autocomplete="on" value="" placeholder="Saisissez une adresse postale ou des coordonnées GPS.">
                        <div class="input-group-addon"><a id="validation" onclick="validSearch();"><span class="glyphicon glyphicon-search"></span></a></div>
                    </div>
            </div>
        </div>

        <ul class="nav navbar-nav navbar-right hidden-xs">
            <li><a href="#" role="button"><span class="glyphicon glyphicon-bell" aria-hidden="true"></span></a></li>
            <li><a href="#" role="button">MyInfo <span class="glyphicon glyphicon-user" aria-hidden="true"></span></a>
            <li class="dropdown">
                <a aria-expanded="false" aria-haspopup="true" role="button" data-toggle="dropdown" class="dropdown-toggle" href="#" id="drop2">
                    <span class="glyphicon glyphicon-th-large"></span>
                </a>
                <ul id="dropdown-services" aria-labelledby="drop2" class="dropdown-menu">
                </ul>
            </li>
        </ul>
    </div>
</nav>

和css:

#search-container {
    padding-top:9px;
}

.pac-container {
    z-index: 9999 !important;
}

问题是自动填充内容列表正在随页面滚动...如何修复自动填充内容列表的位置(.pac-container Google maps css类)?

以下是我的问题的Codepen版本:http://codepen.io/anon/pen/JYezWW

1 个答案:

答案 0 :(得分:0)

由于您使用的是已修复的导航栏,因此您可以将以下内容添加到样式表中,以覆盖您从Google获得的默认样式:

.pac-container {
   position: fixed!important;
   top: 43px!important; /* This is the #search-container height + the padding top */
}