Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter Bootstrap Input Append not full width of container

I have a website build on Twitter Bootstrap.

When building a 2 column form, I am trying to use the input-prepend class to add an email icon to the left of a form input. I want the input field along with the prepend icon to always be 100% of the container.

Here's my code:

                      <div class='row-fluid'>
                        <div class='span6'>
                          <div class='control-group' id='contactEmailControlGroup'>
                            <label for='contactEmail'>Email Address</label>
                              <div class='input-prepend'> <span class='add-on'><i class='icon-envelope'></i></span>
                                <input type='email' name='contactEmail' id='contactEmail' class='span11' placeholder='Your email address...' tabindex='3' required/>
                                <span class='help-inline formAlert' id='contactEmailError'> <i class='icon-edit formAlertIcon'></i> Please enter your email address </span> <span class='help-inline formAlert' id='contactEmailInvalidError'> <i class='icon-exclamation-sign formAlertIcon'></i> Invalid email address </span>
                            </div>
                          </div>
                        </div>
                        <div class='span6'>
                          <div class='control-group'>
                            <label for='contactPhone'>Phone Number</label>
                            <input type='tel' name='contactPhone' id='contactPhone' class='span12' placeholder='Your phone number...' tabindex='4' required/>
                            <span class='help-inline formAlert' id='contactPhoneError'> <i class='icon-edit formAlertIcon'></i> Please enter your phone number </span> <span class='help-inline formAlert' id='contactPhoneInvalidError'> <i class='icon-exclamation-sign formAlertIcon'></i> Invalid phone number </span> </div>
                        </div>
                      </div>

When using this code, the form looks like this screenshot: Form correctly displaying on desktop

But when I resize the browser to simulate a smaller screen, the width of the field with the add-on prepended is sized incorrectly, as seen here: Form incorrectly displaying on tablet and phone

QUESTION

  • Is there a different way this form should be coded so that the input field & icon are 100% and match the other fields?
  • Or What CSS do I need to change in Bootstrap to change this?
like image 881
adamdehaven Avatar asked Jan 02 '13 17:01

adamdehaven


2 Answers

Bootstrap 3 is not out yet, so here is my simple and working solution for both append and prepend cases. Include this after Bootstrap CSS/LESS files:

.input-append.input-block-level,
.input-prepend.input-block-level {
  display: table;
}

.input-append.input-block-level .add-on,
.input-prepend.input-block-level .add-on {
  display: table-cell;
  width: 1%; /* remove this if you want default bootstrap button width */
}

.input-append.input-block-level > input,
.input-prepend.input-block-level > input {
  box-sizing: border-box; /* use bootstrap mixin or include vendor variants */
  display: table; /* table-cell is not working well in Chrome for small widths */
  min-height: inherit;
  width: 100%;
}

.input-append.input-block-level > input {
  border-right: 0;
}

.input-prepend.input-block-level > input {
  border-left: 0;
}

Use it like this in your HTML and remember, you have to use a tags not button for your buttons in this case:

<div class="input-append input-block-level">
  <input type="text" />
  <a class="btn add-on">click</a>
</div>
like image 155
Jan Peša Avatar answered Oct 18 '22 22:10

Jan Peša


Turns out this is a known issue and will be addressed in version 3. [SOURCE]

like image 7
adamdehaven Avatar answered Oct 18 '22 23:10

adamdehaven