Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Bootstrap side by side fields alignment issue for missing labels

I am trying to create a simple bootstrap layout but having trouble aligning controls that do not have labels.

My issue is replicated in below fiddle. The controls (textbox and button) on third column do not have labels, therefore these controls are not aligning next to the Last name text box. I have tried using mt-2 class as well align-bottom but without any success. Can someone please help?

fiddle

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The html is given below.

<div class="row">
                     <div class="col-xs-4 col-lg-4">
            <label for="firstNameInput" class="control-label">First Name</label>

           
                <input type="text" id="firstNameInput" class="form-control" />
            </div>


 <div class="col-xs-6 col-lg-5">
            <label for="lastNameInput" class="control-label">Last Name</label>            
          
                <input type="text" id="lastNameInput" class="form-control" />
            </div>
<div class="col-xs-2 col-lg-1 mt-5 align-baseline">   
        <input type="text" class="form-control" />
    </div>
    
</div>
<div class="row">
                     <div class="col-xs-4 col-lg-4">
            <label for="firstNameInput" class="control-label">First Name</label>

           
                <input type="text" id="firstNameInput" class="form-control" />
            </div>


 <div class="col-xs-6 col-lg-5">
            <label for="lastNameInput" class="control-label">Last Name</label>            
          
                <input type="text" id="lastNameInput" class="form-control" />
            </div>
<div class="col-xs-2 col-lg-1 mb-0 align-baseline">   
        <input type="submit" value="Submit" class="btn btn-primary" />
    </div>
    
</div>

The red line below shows the alignment issue. The controls on the third column should aligned with Last name text boxes.

enter image description here

Thank you

>Solution :

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
  <div class="col-xs-4 col-lg-4">
    <label for="firstNameInput" class="control-label">First Name</label>


    <input type="text" id="firstNameInput" class="form-control" />
  </div>


  <div class="col-xs-6 col-lg-5">
    <label for="lastNameInput" class="control-label">Last Name</label>

    <input type="text" id="lastNameInput" class="form-control" />
  </div>
  <div class="col-xs-2 col-lg-1 d-flex align-items-end">
    <input type="text" class="form-control" />
  </div>

</div>
<div class="row">
  <div class="col-xs-4 col-lg-4">
    <label for="firstNameInput" class="control-label">First Name</label>


    <input type="text" id="firstNameInput" class="form-control" />
  </div>


  <div class="col-xs-6 col-lg-5">
    <label for="lastNameInput" class="control-label">Last Name</label>

    <input type="text" id="lastNameInput" class="form-control" />
  </div>
  <div class="col-xs-2 col-lg-1 mb-0 d-flex align-items-end">
    <input type="submit" value="Submit" class="btn btn-primary" />
  </div>

</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading