Built-in bootstrap form with labels above inputs

How can I move the search button flush with other text fields?

enter image description here

  <form>
       <div class="col-md-3 form-group">
         <label for="search">Title</label>
         <input type="text" name="search" id="search" class="form-control" />
       </div>
       <div class="col-md-2 form-group">
         <label for="created_at_gt">Created at from</label>
         <input type="text" name="created_at_gt" id="created_at_gt" class="form-control" />
       </div>
       <div class="col-md-2 form-group">
         <label for="created_at_lt">To</label>
         <input type="text" name="created_at_lt" id="created_at_lt" class="form-control" />
       </div>
       <div class="row align-center">
         <input type="submit" value="search" class="btn btn-primary" />
        </div>
    </form>

      

+4


source to share


3 answers


An easy fix is ​​to add the same structure as the other input fields (also avoid adding extra CSS that may not cover all cases), use &nbsp;

as placeholder for the label .



<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<br><br><br><br><br><!-- ignore those br, just for stackoverflow full page view -->


<form>
  <div class="col-md-3 form-group">
    <label for="search">Title</label>
    <input type="text" name="search" id="search" class="form-control" />
  </div>
  <div class="col-md-2 form-group">
    <label for="created_at_gt">Created at from</label>
    <input type="text" name="created_at_gt" id="created_at_gt" class="form-control" />
  </div>
  <div class="col-md-2 form-group">
    <label for="created_at_lt">To</label>
    <input type="text" name="created_at_lt" id="created_at_lt" class="form-control" />
  </div>
  <div class="col-md-1 form-group align-center">
    <label for="created_at_lt">&nbsp;</label>
    <input type="submit" value="search" class="btn btn-primary form-control" />
  </div>
</form>
      

Run codeHide result


+6


source


Another easy way is to add the height of the label as a margin.

Make sure you go to the full snippet view to see the correct result:



.lowered {
  margin-top: 25px;
}
      

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<br><br><br><br><br><!-- ignore those br, just for stackoverflow full page view -->


<form>
  <div class="col-md-3 form-group">
    <label for="search">Title</label>
    <input type="text" name="search" id="search" class="form-control" />
  </div>
  <div class="col-md-2 form-group">
    <label for="created_at_gt">Created at from</label>
    <input type="text" name="created_at_gt" id="created_at_gt" class="form-control" />
  </div>
  <div class="col-md-2 form-group">
    <label for="created_at_lt">To</label>
    <input type="text" name="created_at_lt" id="created_at_lt" class="form-control" />
  </div>
  <div class="col-md-2 form-group align-center">
    <input type="submit" value="search" class="btn btn-primary form-control lowered" />
  </div>
</form>
      

Run codeHide result


+1


source


Try using the br tag at the end of the label tag

<div class="row">
<div class="col-md-6">
    <label for="search">Title</label><br>
    <input type="text" name="search" id="search" class="form-control" />
</div>
<div class="col-md-6">
    <label for="year">Year</label><br>
    <input type="text" name="year" id="year" class="form-control" />
</div>
</div>

      

0


source







All Articles