当另一个字段有反馈时,bootstrap-4输入组为什么会伸展?

时间:2019-02-04 20:01:35

标签: forms bootstrap-4 feedback

我有一个表格,可以在一行中包含多个输入组。我正在尝试使用无效反馈(类)来提供表单反馈,但是当我这样做时,相邻字段在垂直方向上被拉伸了。以下代码是一个简单的示例,其中包含2行和2行输入,显示了当右列中有反馈时如何扩展左列。非常感谢您的帮助。

<div class="container mt-3">
  <div class="row">
    <div class="input-group mb-3 col-6">
      <div class="input-group-prepend">
        <span class="input-group-text" id="basic-addon1">First:</span>
      </div>
      <input type="text" class="form-control" placeholder="First" aria-label="First" aria-describedby="basic-addon1">
      <div class="invalid-feedback">Should not show</div>
    </div>
    <div class="input-group mb-3 col-6">
      <div class="input-group-prepend">
        <span class="input-group-text" id="basic-addon2">Second:</span>
      </div>
      <input type="text" class="form-control is-invalid" placeholder="Second" aria-label="Second" aria-describedby="basic-addon2">
      <div class="invalid-feedback">Some text</div>
    </div>
    <div class="input-group mb-3 col-6">
      <div class="input-group-prepend">
        <span class="input-group-text" id="basic-addon3">Third:</span>
      </div>
      <select class="form-control" id="exampleFormControlSelect1" aria-describedby="basic-addon3">
        <option>1</option>
        <option>2</option>
        <option>3</option>
        <option>4</option>
        <option>5</option>
      </select>
      <div class="invalid-feedback">Should not show</div>
    </div>
    <div class="input-group mb-3 col-6">
      <div class="input-group-prepend">
        <span class="input-group-text" id="basic-addon4">Fourth:</span>
      </div>
      <input type="text" class="form-control is-invalid" placeholder="Fourth" aria-label="Fourth" aria-describedby="basic-addon4">
      <div class="invalid-feedback">Some other text</div>
    </div>
  </div>
</div>

jsfiddle:https://jsfiddle.net/8e2uo4jL/

1 个答案:

答案 0 :(得分:0)

我不知道这是否是您需要的,但是您应该使用align-self-start并同时启用d-flex

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container mt-3">
  <div class="row">
    <div class="input-group mb-3 col-6 align-self-start d-flex">
      <div class="input-group-prepend">
        <span class="input-group-text" id="basic-addon1">First:</span>
      </div>
      <input type="text" class="form-control" placeholder="First" aria-label="First" aria-describedby="basic-addon1">
      <div class="invalid-feedback">Should not show</div>
    </div>
    <div class="input-group mb-3 col-6">
      <div class="input-group-prepend">
        <span class="input-group-text" id="basic-addon2">Second:</span>
      </div>
      <input type="text" class="form-control is-invalid" placeholder="Second" aria-label="Second" aria-describedby="basic-addon2">
      <div class="invalid-feedback">Some text</div>
    </div>
    <div class="input-group mb-3 col-6 align-self-start d-flex">
      <div class="input-group-prepend">
        <span class="input-group-text" id="basic-addon3">Third:</span>
      </div>
      <select class="form-control" id="exampleFormControlSelect1" aria-describedby="basic-addon3">
        <option>1</option>
        <option>2</option>
        <option>3</option>
        <option>4</option>
        <option>5</option>
      </select>
      <div class="invalid-feedback">Should not show</div>
    </div>
    <div class="input-group mb-3 col-6">
      <div class="input-group-prepend">
        <span class="input-group-text" id="basic-addon4">Fourth:</span>
      </div>
      <input type="text" class="form-control is-invalid" placeholder="Fourth" aria-label="Fourth" aria-describedby="basic-addon4">
      <div class="invalid-feedback">Some other text</div>
    </div>
  </div>
</div>