cssbootstrap-4sizing

Sizing of Custom-Select Labels in Bootstrap 4


I have a problem with sizing of input elements. When iam creating an input-group (with bootstrap 4.5) and then want them to be input-group-sm, only the custom select fields are in small size, the labels in front of them are in normal size.

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<form>
  <div class="input-group input-group-sm mb-2">
    <div class="input-group-prepend">
      <label class="input-group-text" for="newsAnzahl">Anzahl</label>
    </div>
    <select class="custom-select" id="newsAnzahl" name="newsAnzahl">
      <option value="3" selected>3</option>
      <option value="10">10</option>
      <option value="20">20</option>
      <option value="50">50</option>
      <option value="100">100</option>
      <option value="200">200</option>
    </select>
    <div class="input-group-prepend">
      <label class="input-group-text" for="newsSortierung">Sortierung</label>
    </div>
    <select class="custom-select" id="newsSortierung" name="newsSortierung">
      <option value="ASC">Aufsteigend</option>
      <option value="DESC" selected>Absteigend</option>
    </select>
    <button id="button_getnewslist" type="button" class="btn btn-primary">Liste aktualisieren</button>
  </div>    
</form>

Examples are taken from here at headlines "Sizing" and "Custom Select" Thanks for help!


Solution

  • The problem is that you defined multiple elements inside your .input-group element.

    Just add multiple .input-group's around your elements as shown in this fiddle:

    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
    <form>
      <div class="input-group input-group-sm mb-2">
        <div class="input-group-prepend">
          <label class="input-group-text" for="newsAnzahl">Anzahl</label>
        </div>
        <select class="custom-select" id="newsAnzahl" name="newsAnzahl">
          <option value="3" selected>3</option>
          <option value="10">10</option>
          <option value="20">20</option>
          <option value="50">50</option>
          <option value="100">100</option>
          <option value="200">200</option>
        </select>
      </div>
      <div class="input-group input-group-sm mb-2">
        <div class="input-group-prepend">
          <label class="input-group-text" for="newsSortierung">Sortierung</label>
        </div>
        <select class="custom-select" id="newsSortierung" name="newsSortierung">
          <option value="ASC">Aufsteigend</option>
          <option value="DESC" selected>Absteigend</option>
        </select>
      </div>
      <button id="button_getnewslist" type="button" class="btn btn-primary">Liste aktualisieren</button>
    </form>

    Result showing the proper behavior

    If you want to align it in one line, just use Bootstrap's grid system as shown in this fiddle:

    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
    <form class="row mt-2">
      <div class="col">
        <div class="input-group input-group-sm mb-2">
          <div class="input-group-prepend">
            <label class="input-group-text" for="newsAnzahl">Anzahl</label>
          </div>
          <select class="custom-select" id="newsAnzahl" name="newsAnzahl">
            <option value="3" selected>3</option>
            <option value="10">10</option>
            <option value="20">20</option>
            <option value="50">50</option>
            <option value="100">100</option>
            <option value="200">200</option>
          </select>
        </div>
      </div>
      
      <div class="col">
        <div class="input-group input-group-sm mb-2">
          <div class="input-group-prepend">
            <label class="input-group-text" for="newsSortierung">Sortierung</label>
          </div>
          <select class="custom-select" id="newsSortierung" name="newsSortierung">
            <option value="ASC">Aufsteigend</option>
            <option value="DESC" selected>Absteigend</option>
          </select>
        </div>
      </div>
      
      <div class="col-3">
        <button id="button_getnewslist" type="button" class="btn btn-sm btn-primary">Liste aktualisieren</button>
      </div>
    </form>

    Result in one .row

    Good luck!