0

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!

Tommy
  • 2,355
  • 1
  • 19
  • 48
seehma
  • 23
  • 1
  • 6

2 Answers2

2

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!

Tommy
  • 2,355
  • 1
  • 19
  • 48
1

I hope that helped.

<!-- CSS only -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">

<!-- JS, Popper.js, and jQuery -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>

<div class="container">
  <form>
    <div class="input-group input-group-sm mb-2">
      <div class="input-group-prepend">
        <span class="input-group-text " for=" newsAnzahl ">Anzahl</span>
      </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 ">
      <div class=" input-group-prepend ">
        <span class=" input-group-text " for=" newsSortierung ">Sortierung</span>
      </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 mt-3 ">Liste aktualisieren</button>
  </form>
</div>
Ahmad Dalao
  • 1,968
  • 1
  • 8
  • 14