Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap - select and button next to each other

I have a <select> and a button next to each other and wanted to style them with bootstrap. Select without class looks like this:

enter image description here

select with class="form-control" looks like this: enter image description here

Notice, that the button is now under select. I'm not sure, which CSS property is responsible for this. What should I change, to have button next to the select?

like image 647
Tschareck Avatar asked Jul 04 '14 11:07

Tschareck


People also ask

How multiple buttons can be created at once in Bootstrap?

Instead of applying button sizing classes to every button in a group, just add .btn-group-* to each .btn-group , including each one when nesting multiple groups.


2 Answers

You can wrap the <select> and the <button> in an input-group:

<div class="input-group">   <select class="form-control">     <option>Select option..</option>     <option>Option 1</option>     <option>Option 2</option>   </select>               <span class="input-group-btn">     <button class="btn btn-default" type="button" tabindex="-1"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>   </span> </div> 

This way you can use a normal form and just group one select and button together.

Check out the JSFiddle example

like image 50
Luke Avatar answered Sep 18 '22 14:09

Luke


Following Boostrap syntax :

You should add form-inline class to your form, see the official doc

Official example

<form class="form-inline" role="form">   <div class="form-group">     <label class="sr-only" for="exampleInputEmail2">Email address</label>     <input type="email" class="form-control" id="exampleInputEmail2" placeholder="Enter email">   </div>   <div class="form-group">     <div class="input-group">       <div class="input-group-addon">@</div>       <input class="form-control" type="email" placeholder="Enter email">     </div>   </div>   <div class="form-group">     <label class="sr-only" for="exampleInputPassword2">Password</label>     <input type="password" class="form-control" id="exampleInputPassword2" placeholder="Password">   </div>   <div class="checkbox">     <label>       <input type="checkbox"> Remember me     </label>   </div>   <button type="submit" class="btn btn-default">Sign in</button> </form> 
like image 42
BENARD Patrick Avatar answered Sep 18 '22 14:09

BENARD Patrick