Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using input-block-level with input-prepend in Twitter Bootstrap 2.3.2

I'm wondering how to make an input field fill available width with input-prepend icons in twitter bootstrap 2.3.2 with responsive layout?

there is a css style in bootstrap input-block-level witch works fine until you prepend your input with an icon... How to get same functionality with prependet input?

<div class="control-group">
  <label class="control-label" for="inputIcon">Email address</label>
  <div class="controls">
    <div class="input-prepend ">
      <span class="add-on"><i class="icon-envelope"></i></span>
      <input class="span2" id="inputIcon" type="text" class="input-block-level">
    </div>
  </div>
</div>
<div class="control-group">
    <label class="control-label" for="inputPassword">Password</label>
    <div class="controls">
      <input type="password" id="inputPassword" placeholder="Password" class="input-block-level">
    </div>
</div>

here is example of code illustrating this problem : http://jsfiddle.net/r3CyL/

like image 485
Danil Avatar asked Aug 24 '13 11:08

Danil


1 Answers

You need to add a little extra CSS

DEMO jsFiddle

.input-prepend.input-block-level {
  display: table; 
}
.input-prepend.input-block-level .add-on {
  display: table-cell;
}
.input-prepend.input-block-level > input {
  width: 100%;
}

You could add border color to input-prepend.input-block-level .add-on { to improve it's appearance.

input-prepend.input-block-level .add-on {
    display: table-cell;
    border-right: #fff;
}

EDITED

Another more involved way of doing it. This is also Bootstrap aproved.

DEMO jsFiddle

.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;
}
like image 58
Kevin Lynch Avatar answered Oct 27 '22 23:10

Kevin Lynch