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

Why are bootstrap-4 input groups stretching when another field has feedback?

我有一个表单可以在一行中包含多个输入组。我正在尝试使用无效反馈 (class) 来提供表单反馈,但是当我这样做时,相邻的字段会被垂直拉伸。以下代码是一个简单示例,包含 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/

我不知道这是否是您需要的,但您应该使用 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>