How to align text below an image in bootstrap?
April 18, 2022Hi Friends 👋,
Welcome To aGuideHub! ❤️
Today, I am going to show you. How to align text below an image in bootstrap with code example.
In a row there are 1 image and text below an image which is responsive.but when coded in bootstrap the image are overlapping when window is resized.
You might need to use <figure>
and <figcaption>
:
<figure>
<img />
<figcaption>Image</figcaption>
</figure>
Let’s look at the following example to understand how it basically works:
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<title> Align text below an image in Bootstrap</title>
</head>
<body>
<div class="container">
<div class="row text-center">
<div class="col-xs-12">
<figure>
<img src="images/shoes.png" alt="" height="300" width="300">
<figcaption>Shoes</figcaption>
</figure>
</div>
</div>
</div>
<!-- Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
</body>
</html>
In the above code, we have used <figure>
and <figcaption>
method to center the align text below an image.
Check the output of the above code example.
All the best 👍