Bootstrap Realizes Elastic Search Box

  • 2021-07-02 23:29:18
  • OfStack

Bootstrap is an open source toolkit launched by Twitter for front-end development. Developed by Twitter designers Mark Otto and Jacob Thornton, it is an CSS/HTML framework.

Next, through this article, we will introduce the code of Bootstrap to realize flexible search box. Let's take a look at it.


<form action="" method="get" class="form-horizontal">
<div class="input-group search-input-group">
<input type="hidden" name="scope" value="1">
<input name="key" autocomplete="off" type="text" class="form-control" placeholder=" Enter the content keyword to search for " >
<span class="input-group-addon">
<button type="submit">
<span class="glyphicon glyphicon-search"></span>
</button> 
</span>
</div>
</form>

Corresponding CSS:


.search-input-group .input-group-addon{
background: white !important; 
}
.search-input-group .form-control{
border-right:0; 
box-shadow:0 0 0; 
border-color:#ccc;
}
.search-input-group{
width: 40%;
}
.search-input-group button{
border:0;
background:transparent;
}
.search-input-group input:focus + button{
z-index:3;
}
.search-input-group input{
-webkit-transition: width 0.2s ease-in-out;
-moz-transition:width 0.2s ease-in-out;
-o-transition: width 0.2s ease-in-out;
transition: width 0.2s ease-in-out;
}
.search-input-group input:focus{
width: 500px;
}

If you want to put the search icon in front of the input box, bootstrap is actually not supported, so you need to customize it yourself.

http://bootsnipp.com/snippets/featured/support-glyph-and-fa-icon-inside-input

Above is the site to introduce you to Bootstrap to achieve a full description of the flexible search box, I hope to help you, if you want to know more content please pay attention to this site website!


Related articles: