Home > Blockchain >  Using bootstrap 5, how can I place my btn button vertically and horizontally in the middle over my t
Using bootstrap 5, how can I place my btn button vertically and horizontally in the middle over my t

Time:01-23

How can I place my btn button vertically and horizontally in the middle over my two images? I'm trying to achieve this:

this.

Here is my button <a href="#" role="button">Link example</a> and I'm using the latest version of bootstrap 5.

MY CODE

<!-- Bootstrap-5 -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">


<!-- Body -->
<div >
  <div >
    <div >
      <a  href="#" role="button">Link example</a>
      <img src="https://via.placeholder.com/1920x1080.jpg" >
      <a  href="#" role="button">Link example</a>
      <img src="https://via.placeholder.com/1920x1080.jpg" >
    </div>
    <div >
      //other code
    </div>
  </div>
</div>

CodePudding user response:

Add d-flex align-items-center justify-content-center to your inner container divs' classes.

d-flex is a utility by bootstrap: https://getbootstrap.com/docs/4.0/utilities/flex/

align-items-center will align vertically and justify-content-center will align vertically

CodePudding user response:

check Center elements, also, you need to move each image and button pair to its separate containers:

<!-- Bootstrap-5 -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">


<!-- Body -->
<div >
  <div >
    <div >
      <a  href="#" role="button">Link example</a>
      <img src="https://via.placeholder.com/1920x1080.jpg" >
    </div>
    <div >
      <a  href="#" role="button">Link example</a>
      <img src="https://via.placeholder.com/1920x1080.jpg" >
    </div>
    <div >
      //other code
    </div>
  </div>
</div>

  •  Tags:  
  • Related