.input-group-addon
has a specific width: 1%;
in Bootstrap v3 for a reason - it's best not to modify it. The correct approach is:
- set a minimum width on it using
min-width: 10rem
(%
, em
, rem
, px
...)
- include a
<span>
inside and float it.
<div class="input-group">
<span class="input-group-addon" style="min-width: 12rem; text-align:right;"><span style="float: left;">I am floating-left</span>$</span>
<input type="text" class="form-control" aria-label="Amount (to the nearest dollar)">
<span class="input-group-addon">.00</span>
</div>
The key here is utilizing min-width
. You can see an example above. Additionally, if necessary, you can disable the min-width
on very narrow devices and hide some text on mobile by wrapping it in a class that hides it or provides a shorter version.
.input-group-addon:first-child {
min-width: 200px;
text-align: right;
}
.input-group-addon .floater {
float: left;
}
.input-group {
margin-bottom: 15px;
}
body {
margin: 0;
display: flex;
flex-direction: column;
align-items:center;
justify-content: center;
min-height: 100vh;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="input-group">
<span class="input-group-addon"><span class="floater">I am floating-left</span>$</span>
<input type="text" class="form-control" aria-label="Amount (to the nearest dollar)">
<span class="input-group-addon">.00</span>
</div>
<div class="input-group">
<span class="input-group-addon"><span class="floater">Floating-left</span>$</span>
<input type="text" class="form-control" aria-label="Amount (to the nearest dollar)">
<span class="input-group-addon">.00</span>
</div>
<div class="input-group">
<span class="input-group-addon"><span class="floater">$</span>Not floating left</span>
<input type="text" class="form-control" aria-label="Amount (to the nearest dollar)">
<span class="input-group-addon">.00</span>
</div>
Note: Avoid using more than one <input>
in an .input-group
!
Also: When using it on only one item, consider setting a right margin on the inner span to complete the layout adjustment. Keep in mind that it will always shrink if there is available space due to the set width:1%
.