Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create connected buttons for form controls with bootstrap 3?

I'm trying to get the buttons on these form controls:

Bootply Example

to look like the controls in this example:

Bootsnipp Example

Basically I am trying to re-create the Bootsnipp example using Bootstrap3 [Bootstrap 3.1.1] form controls.

Here is the HTML:

<div class="container">

  <div class="row">

    <div class="controls"> 

      <div class="entry form-group col-sm-4">
        <div class="input-group">
          <input class="form-control" name="fields[]" type="text" placeholder="Type something">
          <button class="btn btn-success btn-add" type="button"><span class="glyphicon glyphicon-plus"></span></button>
        </div>
      </div>

      <div class="entry form-group col-sm-4">
        <div class="input-group">
          <input class="form-control" name="fields[]" type="text" placeholder="Type something">
          <button class="btn btn-success btn-add" type="button"><span class="glyphicon glyphicon-plus"></span></button>
        </div>
      </div>

      <div class="entry form-group col-sm-4">
        <div class="input-group">
          <input class="form-control" name="fields[]" type="text" placeholder="Type something">
          <button class="btn btn-success btn-add" type="button"><span class="glyphicon glyphicon-plus"></span></button>
        </div>
      </div>

    </div>

  </div>

</div>

UPDATE

Would up using a bootstrap form generator that gave me this:

<div class="tag-controls"> 

        <div class="entry col-sm-4 form-group ">
          <div class="input-group">
            <input class="form-control" name="tags[]" type="text" placeholder="Type something" />
            <div class="input-group-btn">
              <button class="btn btn-success btn-add" type="button" data-target="tag-controls"><span class="glyphicon glyphicon-plus"></span></button>
            </div>
          </div>
        </div>

      </div>

Similar to Shawn's answer, which I didn't try I found most of these solutions broke when trying to apply the column sizing to a parent element.

like image 980
Sean Kimball Avatar asked Jul 27 '14 16:07

Sean Kimball


People also ask

How do I create a button link in Bootstrap?

Use the . btn-link class in Bootstrap to create a button look like a link.

How can I put two buttons on the same line in Bootstrap?

Use the . btn-group class in Bootstrap to group buttons on a single like.

How do I make two buttons side by side in Bootstrap?

You can use an out div with a class btn-group . This helps to align the buttons horizontally. Using col-md-6 for each button div can make the buttons missaligned with unwanted space in between.

How do you create the buttons button Group in Bootstrap and what are the classes involved here?

Instead of applying button sizing classes to every button in a group, just add . btn-group-* to each . btn-group , including each one when nesting multiple groups.


2 Answers

You need to wrap the button in a span with class .input-group-btn like so:

<input class="form-control" name="fields[]" type="text" placeholder="Type something">
<span class="input-group-btn"><!-- DO THIS -->
  <button class="btn btn-success btn-add" type="button">
    <span class="glyphicon glyphicon-plus"></span>
  </button>
</span>

DEMO: http://www.bootply.com/BNUUlFK5xX

like image 133
Shawn Taylor Avatar answered Nov 15 '22 05:11

Shawn Taylor


You were missing classes and wrappers and had others that I am not familiar with with 3.x

http://www.bootply.com/V5fU59ukqE

<div class="container">

      <div class="row">


            <div class="col-sm-4">
              <div class="input-group">
              <input class="form-control" name="fields[]" placeholder="Type something" type="text">
              <span class="input-group-btn">
              <button class="btn btn-success" type="button"><span class="glyphicon glyphicon-plus"></span></button>
              </span>
            </div>
           </div>

            <div class="col-sm-4">
              <div class="input-group">
              <input class="form-control" name="fields[]" placeholder="Type something" type="text">
              <span class="input-group-btn">
              <button class="btn btn-success" type="button"><span class="glyphicon glyphicon-plus"></span></button>
              </span>
            </div>
           </div>

            <div class="col-sm-4">
              <div class="input-group">
              <input class="form-control" name="fields[]" placeholder="Type something" type="text">
              <span class="input-group-btn">
              <button class="btn btn-success" type="button"><span class="glyphicon glyphicon-plus"></span></button>
              </span>
            </div>
           </div>


      </div>

    </div>

For Vertical spacing when it collapses, you need yet another wrapper (Bootstrap forms are wrapper heavy) just inside the column "form-group":

<div class="col-sm-4">
              <div class="form-group">
              <div class="input-group">
              <input class="form-control" name="fields[]" placeholder="Type something" type="text">
              <span class="input-group-btn">
              <button class="btn btn-success" type="button"><span class="glyphicon glyphicon-plus"></span></button>
              </span>
            </div>
           </div>
    </div>
like image 44
Christina Avatar answered Nov 15 '22 05:11

Christina