Create Cool Search Box Form In The Navbar Bootstrap

Programming tutorial – in this tutorial I will share about how to create cool search box form in the navbar bootstrap, the search box form useful for reducing limitations of place on the navbar bootstrap. Display search box form will look like the following picture

programming tutorial - create cool search box form in navbar bootstrap 1
programming tutorial - create cool search box form in navbar bootstrap 2

This Navbar is running well on fixed top navbar bootstrap

Let’s begin the tutorial

 Create cool search box form navbar bootstrap

Create new navbar bootstrap like below


<nav class="navbar navbar-default navbar-fixed-top">

<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" aria-expanded="false">
        <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</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">

<li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>

<li><a href="#">Link</a></li>

<li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>

<ul class="dropdown-menu">

<li><a href="#">Action</a></li>

<li><a href="#">Another action</a></li>

<li><a href="#">Something else here</a></li>

<li role="separator" class="divider"></li>

<li><a href="#">Separated link</a></li>

<li role="separator" class="divider"></li>

<li><a href="#">One more separated link</a></li>

          </ul>

        </li>

      </ul>

    </div>

<!-- /.navbar-collapse -->

<div class="container searchbardiv" id="formsearch">

<form role="search" method="get" id="searchform"  >

<div class="input-group">
                        <input type="text" id="searchbox" class="form-control" name="s" id="s">

<div class="input-group-btn">
                            <button class="btn btn-default"  id="searchsubmit"  type="submit">
                                <strong>Search</strong>
                            </button>
                            
                        </div>

                    </div>

                </form>

            </div>

  </div>

<!-- /.container-fluid -->
  <button type="button" class="buttonsearch" id="buttonsearch">
            <i class="glyphicon glyphicon-search openclosesearch"></i><i class="glyphicon glyphicon-remove openclosesearch" style="display:none"></i>
        </button>
</nav>

<div class="jumbotron">

<h1>Hello guys,</h1>

This is example cool search box form in the navbar bootstrap, to get full code and tutorial please visit 

<a class="btn btn-primary btn-lg" href="http://seegatesite.com" role="button">seegatesite.com</a>

</div>

Then add the following css below

.searchbardiv{
    display: block;
    position: fixed;
    background: #7D1935 ;
    top: 50px;
    right: 0px;
    z-index: 1001;
    width: 100%;
    max-width: 100%;
    padding: 10px;
    margin: 0px;
}
.buttonsearch{
    position: fixed;
    top :18px;
    float: right;
    right: 0px;
    margin-right: 10px;
    background-color: transparent;
    border: 0px;
    -webkit-box-shadow: none;
    -moz-box-shadow: none;
    box-shadow: none;
}
.buttonsearch:hover{
    -webkit-box-shadow: none;
    -moz-box-shadow: none;
    box-shadow: none;
    border: 0px;

}
.buttonsearch:focus{
    -webkit-box-shadow: none;
    -moz-box-shadow: none;
    box-shadow: none;
    border: 0px;

}
#formsearch{
    display: none;
}
.glyphicon.glyphicon-search {
    font-size: 18px;
}
#searchbox {
    
    box-shadow: none;
    padding: 8px 14px;
}
#searchbox:hover {
    box-shadow: none;
}

.form-control:focus {
    border-color: #ccc;
    }

.navbar-toggle {
    margin-right: 35px;
    border: none;
    background: transparent !important;
}
.navbar-toggle:hover {
    background: transparent !important;
}
.navbar-toggle .icon-bar {
    width: 22px;
    transition: all 0.2s;
}
.navbar-toggle .top-bar {
    transform: rotate(45deg);
    transform-origin: 10% 10%;
}
.navbar-toggle .middle-bar {
    opacity: 0;
}
.navbar-toggle .bottom-bar {
    transform: rotate(-45deg);
    transform-origin: 10% 90%;
}
.navbar-toggle.collapsed .top-bar {
    transform: rotate(0);
}
.navbar-toggle.collapsed .middle-bar {
    opacity: 1;
}
.navbar-toggle.collapsed .bottom-bar {
    transform: rotate(0);
}

So the search button can run a well, add the jquery function as below

$('#buttonsearch').click(function(){
                $('#formsearch').slideToggle( "fast",function(){
                     $( '#content' ).toggleClass( "moremargin" );
                } );
                $('#searchbox').focus()
                $('.openclosesearch').toggle();
        });

Finish, you can use these tutorial create search box navbar above to beautify your pages. Please see demo on the button below

programming tutorial - demo cool search box form in navbar bootstrap

So my tutorial about how to create cool search box form In the navbar bootstrap, hope it is useful 🙂

The following two tabs change content below.
This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.

Leave a Comment

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.

%d bloggers like this: