4

目前使用 bootstrap-2.1.1

我有一个row-fluid包含 2 列的列,在这些列中我有输入前缀。这是一个示例代码:

<div class="row-fluid">
   <div class="span6">
      <ul>
         <li>
            <div class="input-prepend box-shadow">
                <span class="add-on">email</span>
                <input type="text" name="email" value="" placeholder="Edit email"/>
            </div>
        </li>
     </ul>
   </div>
   <div class="span6">
      <ul>
         <li>
             <div class="input-prepend box-shadow">
               <span class="add-on">name</span>
               <input type="text" name="name" value="" placeholder="Edit name"/>
             </div>
         </li>

      </ul>
    </div>
</div>

你可以在这里看到 JSBIN:http ://jsbin.com/unuruh/1/

问题

如何仅input-prepend使用首选 CSS使父项的输入字段全宽(并使用浏览器调整大小) ?请记住,add-on应该是相同的宽度......

在此先感谢您的帮助。

4

1 回答 1

8

Fluid spans

Here is an approach : Demo (jsbin)

<li>
  <div class="row-fluid">
    <div class="input-prepend box-shadow clearfix" style="border-radius: 3px;">
     <span class="add-on span2" style="width: 14.2%;float: left;">email</span>
     <input class="span1" style="width: 85.8%;float: left;border-right: 0;border-tradius: 0;border-bottom-right-radius: 0;" type="text" name="#" value="#hello" placeholder="Edit project"/>
   </div>
  </div>
</li>

The width and float are there to override what the responsive behavior is doing to spans, the rest of the inline style is to make the box a little bit prettier.

There is a similar question, without all the wrapper problems : Fluid input-append in Bootstrap Responsive


Absolute positioning

Update version 2.3 : you need .input-fullwidth { display: block; }, Updated Demo (jsfiddle)

Another approach would be with absolute positioning : Demo (jsfiddle)

.input-prepend.input-fullwidth {
    position: relative;
}
.input-prepend.input-fullwidth .add-on {
    width: 40px;
}
.input-prepend.input-fullwidth .input-wrapper {
    position: absolute;
    display: block;
    left: 51px; /* 40 + 2*5 - 1 */
    right: 0;
    top: 0;
    bottom: 0;
}
.input-prepend.input-fullwidth .input-wrapper input {
    width: 100%;
    height: 100%;
  -webkit-box-sizing: border-box;
     -moz-box-sizing: border-box;
          box-sizing: border-box;
}
<div class="input-prepend input-fullwidth">
    <span class="add-on">email</span>
    <div class="input-wrapper"><input type="text" name="#" value="#hello" placeholder="Edit project"/></div>
</div>

Ultimately, you may be looking for the flexbox feature of CSS3 (w3.org)

于 2012-10-21T09:14:08.447 回答