Why does using an input group break the baseline alignment in bootstrap?

前端 未结 1 1246
天涯浪人
天涯浪人 2021-01-14 09:22

If I have a form with a label next to an input, in plain HTML, and both are inline (or inline block), then they are aligned by their baseline. But when using bootstrap and p

相关标签:
1条回答
  • 2021-01-14 10:06

    Because the input group is display: inline-table; and the label is outside the input-group. If you inspect the input-group-addon element, you see that it is set to display: table-cell; and vertical-align: middle;. If you move the label inside the input-group and style it same as the input-group-addon it lines up correctly.

    <div class="form-group with-input-group">    
        <div class="input-group">
            <label>label</label>
            <input type="text" class="form-control" value="value" />
            <span class="input-group-addon">addon</span>
        </div>
    </div>
    

    .

    .input-group label {
        padding: 4px;
        display: table-cell;
        vertical-align: middle;
    }
    

    http://jsfiddle.net/N62he/

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