Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fluid input-append in Bootstrap Responsive

I've been struggling to get an input with an input-append element to have the correct width in a fluid layout. I'm using v2.0.4 of Bootstrap. As I resize to make the page smaller it breaks onto a newline. Ideally I'd have the input the full width of the well (like the alerts). I've included the markup and some screenshots below. Any help much appreciated!

<div class="row-fluid">
    <div class="span3 well">
       <form class="form-horiztonal">
           <h2>Filters</h2>
           <fieldset>
               <div class="control-group">
                   <label class="control-label" for="msisdn">MSISDNs</label>
                   <div class="controls">
                       <div class="input-append">
                           <input class="span10" id="msisdn" size="" type="text" name="msisdn"><button
                           class="btn btn-primary" type="submit"><i class="icon-plus icon-white"></i></button>
                       </div>
                   </div>
                </div>
           </fieldset>
       </form>
    </div>

    <div class="span9"></div>
</div>

enter image description here

enter image description here

like image 527
Toby Cronin Avatar asked Jun 25 '12 12:06

Toby Cronin


3 Answers

Since your input is a .span10, the button should be a .span2.

<div class="input-append">
    <input class="span10" id="msisdn" size="" type="text" name="msisdn"><button class="btn btn-primary span2" type="submit"><i class="icon-plus icon-white"></i></button>
</div>

But the behavior of the button radically changes. You can fix it with this css :

.input-append .btn {
    float: none!important;
    margin-left: 0!important;
}

And to be even more precise, the button should be as large as a .span2 plus the fluidGridGutterWidth. Which is width: 17.02127659% according to the default values.

like image 128
Sherbrow Avatar answered Nov 16 '22 05:11

Sherbrow


replace <form class="form-horiztonal"> with <form id="formfilters" class="form-horiztonal">

Add the following jQuery code.

function sizing() {
  var formfilterswidth=$("#formfilters").width();
  $("#msisdn").width((formfilterswidth-46)+"px");
}
$(document).ready(sizing);
$(window).resize(sizing);​

And it allways looks good

Small:

enter image description here

Large:

enter image description here

like image 4
baptme Avatar answered Nov 16 '22 05:11

baptme


The responsive css is what's tripping this up.

By overriding some of the responsive css using

  #msisdn {
    width: 75%;
    display: inline-block;
  }

hopefully you can see what's happening. This will get you close enough hopefully.

like image 2
Declan Cook Avatar answered Nov 16 '22 05:11

Declan Cook