0

I tried using mx-auto to center an image inside a Bootstrap 4 card just below the ard-text but the image is left-justified still.

img src="my.svg" class="mx-auto" alt="...">

I tried to put the img inside a div then text-center but did not work.

How do you center it?

Harshith J Poojary
  • 316
  • 10
  • 26
Juan Tamad
  • 91
  • 1
  • 6

2 Answers2

1

Use mx-auto d-block

<div class="container">
    <div class="row">
        <div class="col">
            <img class="mx-auto d-block" src="...">  
        </div>
    </div>
</div>

Check this for more

Live example on Codeply

John Kreeda
  • 104
  • 6
0

Just need to add a class .center-block in the img tag, looks like this

<div class="container">
  <div class="row">
    <div class="span4"></div>
    <div class="span4"><img class="center-block" src="picture.png"/></div>
    <div class="span4"></div>
  </div>
</div>

In Bootstrap already has css style call .center-block

.center-block {
    display: block;
    margin-left: auto;
    margin-right: auto;
 }

You can see a sample from here

If it doesn't work then use Use mx-auto d-block

Harshith J Poojary
  • 316
  • 10
  • 26