2

I want to add "month" after the input in bootstrap, in the side of it. I've tried span, pull-left nothing worked. Months is always below

<form role="form">
<div class="form-group">
<label for="exampleInputEmail1">Months</label>
<input type="email" class="form-control" style="width: 50%" id="exampleInputEmail1" placeholder="Months"> months
</div>
</form>

JSFIDDLE

Igor Martins
  • 2,015
  • 7
  • 36
  • 57
  • You would need to wrap 'month` with a tag in order to manipulate it. – Josh Crozier Mar 07 '14 at 01:32
  • don't forget to select an answer :) – blurfus Mar 07 '14 at 18:40
  • Related: [How to add text before input element using JavaScript?](https://stackoverflow.com/questions/62557615/how-to-add-text-before-input-element-using-javascript), [How to put text in front of the input form?](https://stackoverflow.com/questions/58781178/how-to-put-text-in-front-of-the-input-form) and [CSS content generation before or after 'input' elements](https://stackoverflow.com/questions/4574912/css-content-generation-before-or-after-input-elements). – joeljpa Apr 21 '23 at 10:36

4 Answers4

3

Just add form-inline to your form..

<form role="form" class="form-inline">
    <div class="form-group">
        <label for="exampleInputEmail1">Months</label>
        <input type="email" class="form-control" style="width: 50%" id="exampleInputEmail1" placeholder="Months"> months
    </div>
</form>

Demo: http://www.bootply.com/119625

Carol Skelly
  • 351,302
  • 90
  • 710
  • 624
1

Try wrapping the elements and specifying the column widths:

HTML

 <form role="form">
  <div class="form-group">
     <div class="pull-left col-xs-9">
        <label for="exampleInputEmail1">Email address</label>
        <input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email">
     </div>
    <span class="col-xs-3">months<span>
  </div>
</form>

CSS

span{
    margin-top: 25px;
}

JS Fiddle: http://jsfiddle.net/7rYp7/2/

Kevin Bowersox
  • 93,289
  • 19
  • 159
  • 189
1

putting style="display:inline" into the actual input element in question has worked for me.

Listen, I know we are supposed to avoid using style and only use classes defined in CSS but I tried all the example above and this is the only thing that worked.

AgilePro
  • 5,588
  • 4
  • 33
  • 56
0

You can set the following in your CSS (overwriting the bootstrap.css)

.form-group input {
    display:inline;
    width: 50%;
    margin: 5px;
}

You can also use a different selector to be more specific (instead of overwriting it for all inputs) UPDATED:

#exampleInputEmail1{
        display:inline;
        width: 50%;
        margin: 5px;
}

.form-group label {
    display: block;
}
blurfus
  • 13,485
  • 8
  • 55
  • 61
  • I see, you want the label to stay on top of the input and the 'month' still next to the input. Did I understand it right? – blurfus Mar 07 '14 at 01:57
  • ok, you can use Kevin's method or the code in the updated fiddle http://jsfiddle.net/blurfus/7rYp7/4/ – blurfus Mar 07 '14 at 02:04