formsbootstrap-4feedback

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


I have a form that can include multiple input groups in one row. I am trying to use invalid-feedback (class) to provide form feedback but adjacent fields are getting stretched vertically when I do this. The following code is a simple example of 2 rows with 2 inputs showing how the left column is stretched when there is feedback in the right column. I'd really appreciate some help with this.

<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/


Solution

  • I don't know if this is what you need but you should use align-self-start and also enable 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>