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

Can't align items – Bootstrap 4.5

I’m trying to align two objects in HTML using Bootstrap, but it’s not working. The code I’m using is this:

<div class="row align-items-center">

  <div class="col-auto">
    <h6>Alignment Testing</h6>
  </div>

  <div class="col-auto ml-auto">
    <!-- ml-auto -->
    <div class="input-group">
      <span class="input-group-text" id="basic-addon1"><i class="bi bi-search"></i></span>
      <input type="text" class="form-control" placeholder="Alignment Testing" aria-label="Username" aria-describedby="basic-addon1">
    </div>
  </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" >

Image of the problem

If I change the "items-align-center" to "items-align-start/end", the text (h6) changes position slightly. The interesting thing is that I applied the "items-align-center" in other places and it worked perfectly. Any idea what it could be? I saw some topics mentioning that the div must have a height, I already tried to put a height and it also did not align in the center.

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

Any ideas?

>Solution :

In your <h6> make mb-0 as h6 occupies margin bottom of 8px

  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css">
  <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.4/dist/jquery.slim.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"></script>
<div class="row align-items-center">
    <div class="col-auto">
        <h6 class="mb-0">Alignment Testing</h6>
    </div>            
    <div class="col-auto ml-auto">
        <div class="input-group">
            <span class="input-group-text" id="basic-addon1"><i class="bi bi-search"></i></span>
            <input type="text" class="form-control" placeholder="Alignment Testing" aria-label="Username" aria-describedby="basic-addon1">
        </div>
    </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