bootstrap 3 input-group 100% width

后端 未结 5 2093
无人及你
无人及你 2021-02-12 23:59

In the bootstrap documentation, they have input groups that span 100% width with no additional markup: http://getbootstrap.com/components/#input-groups

相关标签:
5条回答
  • 2021-02-13 00:41

    Adding width: 1% to the input element's sibling fixes this:

    .clear { width: 1%; display: table-cell; }
    

    See http://jsfiddle.net/Wexcode/B9LMN/2/

    0 讨论(0)
  • 2021-02-13 00:43
    <div class="container">
    <h3>Form widths</h3>
    
    <form role="form">
      <div class="form-group">
        <label>Auto width</label>
    
        <div class="input-group">
          <input class="form-control" placeholder="Auto width" /> <span class=
          "input-group-addon"><a href="#" class="glyphicon glyphicon-remove"></a></span>
        </div>
      </div>
    
      <div class="form-group">
        <label>100% width</label>
    
        <div class="input-group" style="width: 100%">
          <input class="form-control" placeholder="100% width" /> <span class=
          "input-group-addon"><a href="#" class="glyphicon glyphicon-remove"></a></span>
        </div>
      </div>
    </form>
    </div>
    
    0 讨论(0)
  • 2021-02-13 00:45

    If you have select2 as a part of your "input-group", you better create it with "resolve" parameter:

    $(document).ready(function() { 
        $("#myselect").select2({ width: 'resolve' });           
    });
    
    0 讨论(0)
  • 2021-02-13 00:55

    One way to get an input-group to stretch to full width seem to give one of its input-group-addon 100% width:

    <div class="input-group" style="width:100%;">
      <span class="one input-group-addon">one</span>
      <span class="two input-group-addon">two</span>
      <span class="tre input-group-addon" style="width:100%">tre</span> <!-- here -->
      <span class="for input-group-addon">for</span>
      <span class="fiv input-group-addon">fiv</span>
      <span class="input-group-btn"> 
         <button class="btn" type="button">x</button> 
      </span>
    </div>
    
    0 讨论(0)
  • 2021-02-13 01:05

    input-group has display: table css property, while the <input class="form-control" has display: table-cell css property.

    <div class="input-group"> <!-- this is display: table -->
      <input type="text" class="form-control"> <!-- this is display: table-cell -->
      <span class="input-group-addon">.00</span> <!-- this is display: table-cell -->
    </div>
    

    According to HERE, under "Important Style Rules for Tables",

    Width works on table cells just about how you would think it does, except when there is 
    some kind of conflict. For instance if you tell the table itself to be 400px wide then the 
    first cell of a three-cell row to be 100px wide and leave the others alone, that first cell
    will be 100px wide and the other two will split up the remaining space. 

    it explains that if the width of the child element that has table-cell is defined (let's say width: 100px), then the next child element with table-cell property, although not defined, will fill in the rest of the space.

    0 讨论(0)
提交回复
热议问题