Why is my Bootstrap input not aligned correctly?

Why does my Bootstrap input not align right (=> see the third entry with placeholder = 'Do not align right')?
The td table element has a style that defines alignment ...
When I remove a style element from the td element when I set the input style text-align = right, it is left-aligned anyway.

<div class="row">
    <div class="col-md-6">
        <div class="well" style="width:840px">
            <table class='table borderless' style="width:800px">
            <tr>
                <td colspan="2">
                    <input class="form-control input-sm" style="width:300px;margin-bottom:0px" type="text" name="input1" placeholder="Input 1">
                    <input class="form-control input-sm" style="width:300px;margin-bottom:0px" type="text" name="input2" placeholder="Input 2">
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: right">
                    <input class="form-control input-sm" style="width:300px;margin-bottom:0px" type="text" name="input3" placeholder="Does not align right">
                </td>
            </tr>
            <tr>
            </table>
        </div>
    </div>
</div>
+4
source share
3 answers

Why is my Bootstrap input not aligned correctly?

Because it .form-controlwill have display: blockfrom bootstrap.min.css. As evidence of this, if you do it again inline-block, it will work:

.form-control { display: inline-block !important; }
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>

<div class="row">
    <div class="col-md-6">
        <div class="well" style="width:840px">
            <table class='table borderless' style="width:800px">
            <tr>
                <td colspan="2">
                    <input class="form-control input-sm" style="width:300px;margin-bottom:0px" type="text" name="input1" placeholder="Input 1">
                    <input class="form-control input-sm" style="width:300px;margin-bottom:0px" type="text" name="input2" placeholder="Input 2">
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: right">
                    <input class="form-control input-sm" style="width:300px;margin-bottom:0px" type="text" name="input3" placeholder="Does not align right">
                </td>
            </tr>
            <tr>
            </table>
        </div>
    </div>
</div>
Run code

, , , , , . Bootstrap form-inline, . :

<div class="row form-inline">

, . form-inline , .

+6

, display, block .form-control. . , .

, display inline-block .pull-right.

.form-control {
    display: inline-block;
}
<input type="text" class="form-control input-sm pull-right">
+3

Twitter Bootstrap width: 100% .form-control, Grid system

HTML

<div class="row">
  <div class="col-md-9 is-centered">
    <div class="well well-form">
     <!-- Two inline input fields per row -->
     <div class="row">
      <div class="col-sm-6 form-group">
       <input class="form-control input-sm" type="text" name="input1" placeholder="Input 1">
      </div>
      <div class="col-sm-6 form-group">
       <input class="form-control input-sm" type="text" name="input2" placeholder="Input 2">
      </div>
     </div>
     <div class="row has-border">
      <div class="col-sm-12">
       <!-- Single input fields per row (pushed to the right) -->
       <div class="row">
       <div class="col-sm-6 pull-right">
        <input class="form-control input-sm" type="text" name="input3" placeholder="align to right">
       </div>
      </div>
      </div>
    </div>
   </div>
  </div>
</div>

Helpers (optional)

SCSS

[class*="col-"] {
 &.is-centered {
    float: none;
    margin-right: auto;
    margin-left: auto;
  } 
}

.well-form {
  > .row {
    padding-top: 8px;
    border-top: 1px solid #ddd;
  }
  .form-group {
    margin-bottom: 8px;
  }
}

CSS

[class*="col-"].is-centered {
  float: none;
  margin-right: auto;
  margin-left: auto;
}

.well-form > .row {
  padding-top: 8px;
  border-top: 1px solid #ddd;
}
.well-form .form-group {
  margin-bottom: 8px;
}

Demo

A few notes:

  • <table> not a good approach in this case
  • inline style="for HTML tags is not very good (even if this is a demo)

Hope this helps

0
source

All Articles