skip to Main Content

I’m trying to create an input form.
The first row contain a column,

The second row contain 2 column,

the third row contain 3 column.

There are label and input in each column

When i try to create the form, the start of the input is different from each row.

Try to use align-self-center order-2 but it’s not working

Source Code

<div class="row mt-3">
  <div class="col-md-12">
    <div class="row mb-3">
      <div class="col-md-2 col-xs-2">
        <label for="Nationality" class="required control-label col-form-label">Nationality</label>
      </div>
      <div class="col-md-10 col-xs-10 align-self-center order-2">
        <input type="text" class="form-control" name="Nationality" id="Nationality" >
      </div>
    </div>
  </div>
</div>

<div class="row justify-content-center mt-3 align-items-center">
  <div class="col-md-6">
    <div class="row mb-3 justify-content-center">
      <div class="col-md-5 col-xs-5">
        <label for="maritalStatus" class="required control-label col-form-label">maritalStatus</label>
      </div>
      <div class="col-md-7 col-xs-7">
        <select class="form-control selecting" id="maritalStatus" name="maritalStatus">
          <option value=""></option>
          <option value="a">a</option>
          <option value="b">b</option>
        </select>
      </div>
    </div>
  </div>
  <div class="col-md-6">
    <div class="row mb-3 justify-content-center">
      <div class="col-md-5 col-xs-5">
        <label for="education" class="required control-label col-form-label">Educaiton</label>
      </div>
      <div class="col-md-7 col-xs-7">
        <select class="form-control selecting" id="education" name="education">
          <option value=""></option>
          <option value="a">a</option>
          <option value="b">b</option>
        </select>
      </div>
    </div>
  </div>
</div>

<div class="row justify-content-center mt-3 align-items-center">
  <div class="col-md-4">
    <div class="row mb-3 justify-content-center">
      <div class="col-md-5 col-xs-5">
        <label for="GHI" class="required control-label col-form-label">GHI</label>
      </div>
      <div class="col-md-7 col-xs-7">
        <select class="form-control selecting" id="GHI" name="GHI">
          <option value=""></option>
          <option value="a">a</option>
          <option value="b">b</option>
        </select>
      </div>
    </div>
  </div>
  <div class="col-md-4">
    <div class="row mb-3 justify-content-center">
      <div class="col-md-5 col-xs-5">
        <label for="DEF" class="required control-label col-form-label">DEF</label>
      </div>
      <div class="col-md-7 col-xs-7">
        <select class="form-control selecting" id="DEF" name="DEF">
          <option value=""></option>
          <option value="a">a</option>
          <option value="b">b</option>
        </select>
      </div>
    </div>
  </div>
  
  <div class="col-md-4">
    <div class="row mb-3 justify-content-center">
      <div class="col-md-5 col-xs-5">
        <label for="ABC" class="required control-label col-form-label">ABC</label>
      </div>
      <div class="col-md-7 col-xs-7">
        <select class="form-control selecting" id="ABC" name="ABC">
          <option value=""></option>
          <option value="a">a</option>
          <option value="b">b</option>
        </select>
      </div>
    </div>
  </div>
</div>

The Result
enter image description here

From the below code, how can i make the start of input of each row is vertically align and make it looks better ? Is there any way just use classes from bootstrap to support it?

2

Answers


  1. Here You will need to add all column in one row and use Column breaks. & then, Add same column width for all label column (For ex: col-md-2 ). as Setting one column width

    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script>
    
    <div class="row g-2 g-md-3 align-items-center">
      <div class="col-md-2">
        <label for="Nationality" class="required control-label col-form-label">Nationality</label>
      </div>
      <div class="col-md">
        <input type="text" class="form-control" name="Nationality" id="Nationality" >
      </div>
      
      <div class="w-100"></div> <!-- Force next columns to break to new line -->
      
      <div class="col-md-2">
        <label for="maritalStatus" class="required control-label col-form-label">maritalStatus</label>
      </div>
      <div class="col-md">
        <select class="form-control selecting" id="maritalStatus" name="maritalStatus">
          <option value=""></option>
          <option value="a">a</option>
          <option value="b">b</option>
        </select>
      </div>
      
      <div class="col-md-2">
        <label for="education" class="required control-label col-form-label">Educaiton</label>
      </div>
      <div class="col-md">
        <select class="form-control selecting" id="education" name="education">
          <option value=""></option>
          <option value="a">a</option>
          <option value="b">b</option>
        </select>
      </div>
      
      <div class="w-100"></div> <!-- Force next columns to break to new line -->
      
      <div class="col-md-2">
        <label for="GHI" class="required control-label col-form-label">GHI</label>
      </div>
      <div class="col-md">
        <select class="form-control selecting" id="GHI" name="GHI">
          <option value=""></option>
          <option value="a">a</option>
          <option value="b">b</option>
        </select>
      </div>
      
      <div class="col-md-2">
        <label for="DEF" class="required control-label col-form-label">DEF</label>
      </div>
      <div class="col-md">
        <select class="form-control selecting" id="DEF" name="DEF">
          <option value=""></option>
          <option value="a">a</option>
          <option value="b">b</option>
        </select>
      </div>
      
      <div class="col-md-2">
        <label for="ABC" class="required control-label col-form-label">ABC</label>
      </div>
      <div class="col-md">
        <select class="form-control selecting" id="ABC" name="ABC">
          <option value=""></option>
          <option value="a">a</option>
          <option value="b">b</option>
        </select>
      </div>
      
    </div>

    Text align right for Label …. more better looks- example below:

    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script>
    
    <div class="row g-2 g-md-3 align-items-center">
      <div class="col-md-2 text-md-end">
        <label for="Nationality" class="required control-label col-form-label">Nationality</label>
      </div>
      <div class="col-md">
        <input type="text" class="form-control" name="Nationality" id="Nationality" >
      </div>
      
      <div class="w-100"></div> <!-- Force next columns to break to new line -->
      
      <div class="col-md-2 text-md-end">
        <label for="maritalStatus" class="required control-label col-form-label">maritalStatus</label>
      </div>
      <div class="col-md">
        <select class="form-control selecting" id="maritalStatus" name="maritalStatus">
          <option value=""></option>
          <option value="a">a</option>
          <option value="b">b</option>
        </select>
      </div>
      
      <div class="col-md-2 text-md-end">
        <label for="education" class="required control-label col-form-label">Educaiton</label>
      </div>
      <div class="col-md">
        <select class="form-control selecting" id="education" name="education">
          <option value=""></option>
          <option value="a">a</option>
          <option value="b">b</option>
        </select>
      </div>
      
      <div class="w-100"></div> <!-- Force next columns to break to new line -->
      
      <div class="col-md-2 text-md-end">
        <label for="GHI" class="required control-label col-form-label">GHI</label>
      </div>
      <div class="col-md">
        <select class="form-control selecting" id="GHI" name="GHI">
          <option value=""></option>
          <option value="a">a</option>
          <option value="b">b</option>
        </select>
      </div>
      
      <div class="col-md-2 text-md-end">
        <label for="DEF" class="required control-label col-form-label">DEF</label>
      </div>
      <div class="col-md">
        <select class="form-control selecting" id="DEF" name="DEF">
          <option value=""></option>
          <option value="a">a</option>
          <option value="b">b</option>
        </select>
      </div>
      
      <div class="col-md-2 text-md-end">
        <label for="ABC" class="required control-label col-form-label">ABC</label>
      </div>
      <div class="col-md">
        <select class="form-control selecting" id="ABC" name="ABC">
          <option value=""></option>
          <option value="a">a</option>
          <option value="b">b</option>
        </select>
      </div>
      
    </div>
    Login or Signup to reply.
  2. Add one more div with wrapper class as a parent div. also add flex alignment classes for vertical and horizontal alignment. give ‘height: 100vh;’ in wrapper class like below code.

    .wrapper {height: 100vh;}

    <div class="row mt-3">
      <div class="col-md-12">
        <div class="row mb-3">
          <div class="col-md-2 col-xs-2">
            <label for="Nationality" class="required control-label col-form-label">Nationality</label>
          </div>
          <div class="col-md-10 col-xs-10 align-self-center order-2">
            <input type="text" class="form-control" name="Nationality" id="Nationality" >
          </div>
        </div>
      </div>
    </div>
    
    <div class="row justify-content-center mt-3 align-items-center">
      <div class="col-md-6">
        <div class="row mb-3 justify-content-center">
          <div class="col-md-5 col-xs-5">
            <label for="maritalStatus" class="required control-label col-form-label">maritalStatus</label>
          </div>
          <div class="col-md-7 col-xs-7">
            <select class="form-control selecting" id="maritalStatus" name="maritalStatus">
              <option value=""></option>
              <option value="a">a</option>
              <option value="b">b</option>
            </select>
          </div>
        </div>
      </div>
      <div class="col-md-6">
        <div class="row mb-3 justify-content-center">
          <div class="col-md-5 col-xs-5">
            <label for="education" class="required control-label col-form-label">Educaiton</label>
          </div>
          <div class="col-md-7 col-xs-7">
            <select class="form-control selecting" id="education" name="education">
              <option value=""></option>
              <option value="a">a</option>
              <option value="b">b</option>
            </select>
          </div>
        </div>
      </div>
    </div>
    
    <div class="row justify-content-center mt-3 align-items-center">
      <div class="col-md-4">
        <div class="row mb-3 justify-content-center">
          <div class="col-md-5 col-xs-5">
            <label for="GHI" class="required control-label col-form-label">GHI</label>
          </div>
          <div class="col-md-7 col-xs-7">
            <select class="form-control selecting" id="GHI" name="GHI">
              <option value=""></option>
              <option value="a">a</option>
              <option value="b">b</option>
            </select>
          </div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="row mb-3 justify-content-center">
          <div class="col-md-5 col-xs-5">
            <label for="DEF" class="required control-label col-form-label">DEF</label>
          </div>
          <div class="col-md-7 col-xs-7">
            <select class="form-control selecting" id="DEF" name="DEF">
              <option value=""></option>
              <option value="a">a</option>
              <option value="b">b</option>
            </select>
          </div>
        </div>
      </div>
      
      <div class="col-md-4">
        <div class="row mb-3 justify-content-center">
          <div class="col-md-5 col-xs-5">
            <label for="ABC" class="required control-label col-form-label">ABC</label>
          </div>
          <div class="col-md-7 col-xs-7">
            <select class="form-control selecting" id="ABC" name="ABC">
              <option value=""></option>
              <option value="a">a</option>
              <option value="b">b</option>
            </select>
          </div>
        </div>
      </div>
    </div>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search