htmlcsstwitter-bootstrapalignment

Align button with input forms with labels


I'm trying to align a button element with two other input elements with labels. Using the bootstrap snippet below:

<div class="row centered-form center-block ">
  <div class="container col-md-6 col-md-offset-3">
    <form action="/result" class="form-inline" method="get" role="form">
      <div class="row">
         <div class="form-group col-md-6">
           <label class="control-label" for="County">Prop1, Prop2</label>
           <input class="form-control" name="County"  type="text" />
         </div>
         <div class="form-group col-md-4">
           <label class="control-label" for="Type">Type of Election</label>
             <select class="form-control" name="Type"><option value=""></option>
                <option value="1">President</option>
             </select>
         </div>
        <button class="btn btn-primary col-md-2" type="submit">Submit</button>
     </div>
   </form>    
  </div>
</div>

The image I'm getting looks like this:

enter image description here

If I remove labels from the two from inputs, I get:

enter image description here

How can I leave labels on the form inputs and still align them with the button?

JSFiddle


Solution

  • Instead of an improper label, use the align-self-end class (bootstrap 4 / flexbox) to vertically align the button to the bottom of the column.

    <div class="form-group col-md-2 align-self-end">
      <button class="btn btn-primary" id="btn" name="btn" type="submit">Submit</button>
    </div>