0

I use bootstrap and I would like to know why when I apply max-width to an image, it does not consider text-center and is decentralized. Just remove the max-width to make it centered again.

<div class="img-rsa g-4 align-self-center text-center">

  <img src="img/aluno-rsa.jpg" alt="" class="img-fluid" style="border-radius:100%">

</div>
.img-rsa {
    width: 100%;
    max-width: 350px;
    display: block;
}
João Pimentel Ferreira
  • 14,289
  • 10
  • 80
  • 109

2 Answers2

0

You would need to apply your width settings to the image.

.img-fluid {
  width: 100%;
  max-width: 350px;
  height: auto: // You need to add this
  display: block;
}

Then since the image is block now, you can use margin auto to center it. Or you can keep the image inline and center it with text-align.

jons
  • 312
  • 2
  • 10
0

Use the class mx-auto on the image to horizontally center it. Run this example based on your specific case:

.img-rsa {
    width: 100%;
    max-width: 350px;
    display: block;
    border: solid 1px black;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.1.0/css/bootstrap-grid.min.css">

<div class="img-rsa g-4 d-flex align-self-center">
  <img src="https://picsum.photos/200" alt="" class="img-fluid mx-auto" style="border-radius: 100%">
</div>
João Pimentel Ferreira
  • 14,289
  • 10
  • 80
  • 109