Dan Tappin
Dan Tappin

Reputation: 3032

Responsive navbar with left brand, centre search form and left dropdown

I am very close on this one!! I have taken the stock BS navbar and customized it. I am looking for a simple nabber with a search field centred in it.

Here is my code: http://www.bootply.com/dxTjFzpv4K

<nav class="navbar navbar-default navbar-inverse">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">Brand Text</a>
        </div>
        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav navbar-search">
                <form class="navbar-form" role="search">
                    <div class="input-group">
                        <input type="text" class="form-control" placeholder="Search" contenteditable="false">
                        <div class="input-group-btn">
                            <button type="button" class="btn btn-default">Search</button>
                        </div>
                    </div>
                </form>
            </ul>
            <ul class="nav navbar-nav navbar-right">
                <li><a href="#" class="">Link</a>
                </li>
                <li class="dropdown">   <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"> Dropdown <span class="caret"></span></a>
                    <ul class="dropdown-menu" role="menu">
                        <li><a href="#" class="">Menu Item 1</a>
                        </li>
                        <li><a href="#" class="">Menu Item 2</a>
                        </li>
                        <li><a href="#" class="">Menu Item 3</a>
                        </li>
                        <li><a href="#" class="">Menu Item 4</a>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
</nav>

and my custom CSS:

.navbar-search
{
    position: absolute;
    width: 100%;
    left: 0;
    text-align: center;
    margin: auto;
}

that I found from another example here: http://www.bootply.com/98314

I renders properly but when you switch to the responsive mode the search field overlaps the collapsed menu items.

As a bonus question - can I make the search field wider? I have tried a few CSS tricks and wrapping it in a BS table and specifing a column width but nothing that works so far.

UPDATE

That answer worked now it's broken again. The field spans 100% and overlaps everything. The funny thing is that the formatting looks great on the responsive mode just not the desktop.

Here is the computed navbar-search class CSS:

box-sizing: border-box;
color: rgb(51, 51, 51);
display: block;
float: none;
font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 14px;
height: 50px;
left: 0px;
line-height: 20px;
list-style-image: none;
list-style-position: outside;
list-style-type: none;
margin-bottom: 0px;
margin-left: 0px;
margin-right: 0px;
margin-top: 0px;
padding-left: 0px;
position: absolute;
text-align: center;
width: 1636px

Upvotes: 0

Views: 1568

Answers (1)

Wild Beard
Wild Beard

Reputation: 2927

position: absolute; on your .navbar-search class is causing the overlapping issue. You can add a media query to change the position. Here is bootply of what I did.

Upvotes: 2

Related Questions