This question already has an answer here:
- Bootstrap 4 center-block unable to center 3 answers
- How do I center an image in Bootstrap? 2 answers
I am new to Bootstrap 4, earlier in Bootstrap 3 we use class "center-block", now I am not able to find this in new version.
Center an inline element has nothing to do with Bootstrap actually.
Center the image using
text-align
An image is a inline element and can be aligned using
text-align
.Text will flow around the image, since it is an inline element.
Normally:
The Bootstrap way:
Center the image using
margin
You can change the display of the image to a block element and use margin to center the block.
Text will be pushed above and under the image since we change the display to
block
.The Bootstrap way:
Full example
This can be done with built-in .d-block:
More info in this link
Try using this code.
html:
css: