Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3 select input form inline

I'm trying to get input and select option inline attached with each other like this demo using Bootstrap 2 (dead link).

Following Bootstrap 3 guidelines I manage to do this:

<div class="container">
    <div class="col-sm-7 pull-right well">
      <form class="form-inline" action="#" method="get">
        <div class="form-group col-sm-5">
          <input class="form-control" type="text" value="" placeholder="Search" name="q">
        </div>
        <div class="form-group col-sm-3">
          <select class="form-control" name="category">
              <option>select</option>
              <option>1</option>
              <option>2</option>
              <option>3</option>
          </select>
        </div>
        <button class="btn btn-primary col-sm-3 pull-right" type="submit">Search</button>
      </form>
    </div>
</div>

It's responsive, but input and select can't be attached without some nasty css hacks. I found lot of examples with attached buttons, but that does not work with select element.

like image 466
Collector Avatar asked Nov 11 '13 11:11

Collector


3 Answers

I think I've accidentally found a solution. The only thing to do is inserting an empty <span class="input-group-addon"></span> between the <input> and the <select>.

Additionally you can make it "invisible" by reducing its width, horizontal padding and borders:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>

<div class="input-group">
    <span class="input-group-addon" title="* Price" id="priceLabel">Price</span>
    <input type="number" id="searchbygenerals_priceFrom" name="searchbygenerals[priceFrom]" required="required" class="form-control" value="0">
    <span class="input-group-addon">-</span>
    <input type="number" id="searchbygenerals_priceTo" name="searchbygenerals[priceTo]" required="required" class="form-control" value="0">
  
    <!-- insert this line -->
    <span class="input-group-addon" style="width:0px; padding-left:0px; padding-right:0px; border:none;"></span>
  
    <select id="searchbygenerals_currency" name="searchbygenerals[currency]" class="form-control">
        <option value="1">HUF</option>
        <option value="2">EUR</option>
    </select>
</div>

Tested on Chrome and FireFox.

like image 143
cinemazealot Avatar answered Oct 17 '22 03:10

cinemazealot


Can be done with pure Bootstrap code.

<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/css/bootstrap.css" rel="stylesheet"/>

<div class="form-group">
  <label for="id" class="col-md-2 control-label">ID</label>
  <div class="input-group">
    <span class="input-group-btn">
      <select class="form-control" name="id" id="id">
        <option value="">
      </select>
    </span>
    <span class="input-group-btn">
      <select class="form-control" name="nr" id="nr">
        <option value="">
      </select>
    </span>
  </div>	
</div>	
like image 25
Daniel Bjørnådal Avatar answered Oct 17 '22 02:10

Daniel Bjørnådal


Thanks to G_money and other suggestions for this excellent solution to input-text with inline dropdown... here's another great solution.

<form class="form-inline" role="form" id="yourformID-form" action="" method="post">
    <div class="input-group">
        <span class="input-group-addon"><i class="fa fa-male"></i></span>

        <div class="form-group">
            <input size="50" maxlength="50" class="form-control" name="q" type="text">          
        </div>

        <div class="form-group">
            <select class="form-control" name="category">
                <option value=""></option>
                <option value="0">select1</option>
                <option value="1">select2</option>
                <option value="2">select3</option>
            </select>           
        </div>
    </div>
</form>

This works with Bootstrap 3: allowing input-text inline with a select dropdown. Here's what it looks like below...

enter image description here

like image 10
Jesse C Avatar answered Oct 17 '22 03:10

Jesse C