Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3: how to control input width inside input-group?

See http://jsfiddle.net/7T9r9/ as an example.

<li>
  <span class="row">
    <div class="col-md-3">
      <div class="input-group">
        <span class="input-group-addon">
          <input type="checkbox" class="checkbox"/>
        </span>
        <input type="text" class="form-control input-append" value="test">
        <span class="input-group-addon"></span>
      </div>
    </div>
    <div class="col-md-9">
      <div class="input-group">
        <input type="text" class="form-control"
               value="test">
        <span class="input-group-addon">
            <a href="#">
              <span class="glyphicon glyphicon-trash"></span>
            </a>
        </span>
      </div>
    </div>
  </span>
</li>

What I would like to achieve is to have the first input width fitting the text inside of it (a fixed width would do as well I guess). The second input should occupy the rest of the row and all the elements should be on the same line.

Is there a way to do this?

like image 577
Nikolay Derkach Avatar asked Dec 13 '13 22:12

Nikolay Derkach


People also ask

How do I change the input-group width in Bootstrap?

To set the width of the input-group-text , just change the value of the flex of the input-group , for instance, as seen above 30% of the total width.

How do I change the input-group width?

Change the size of the input groups, by adding the relative form sizing classes like . input-group-lg, input-group-sm, input-group-xs to the . input-group itself.

What is input-group prepend?

input-group class is a container to enhance an input by adding an icon, text or a button in front or behind the input field as a "help text". Use . input-group-prepend to add the help text in front of the input, and . input-group-append to add it behind the input.

How do I make a small text box in Bootstrap?

Use the . input-sm class to set small input field in Bootstrap.


1 Answers

I'm guessing your fiddle is an example of the effect that you want, but you don't want to use different columns for it.

  1. Dynamic width Text input based on value length is not possible (unless recently via some css goddess like Verou finding something). So assuming fixed width on that guy.
  2. The other guy then can take advantage of the other fixed width to do a margin etc.

Something like this:

HTML

  <span class="row">
      <div class="test1 input-group">
        <span class="input-group-addon">
          <input type="checkbox" class="checkbox"/>
        </span>
        <input type="text" class="form-control input-append" value="test">
        <span class="input-group-addon"></span>
      </div>
      <div class="test2 input-group">
        <input type="text" class="form-control"
               value="test">
        <span class="input-group-addon">
            <a href="#">
              <span class="glyphicon glyphicon-trash"></span>
            </a>
        </span>
      </div>
  </span>

CSS

.row {
    position:relative;    
}
.test1 {
    width:200px
}
.test2 {
    position:absolute !important;
    top:20px;
    margin-left:200px;
}
like image 84
Nick Sharp Avatar answered Sep 29 '22 22:09

Nick Sharp