Bootstrap card design (background image)

Bootstrap 5 category card with a background image using only Bootstrap classes.

Final Output:

Bootstrap card design background image
Lamps


1. Add the Bootstrap image overlay card. Add your image and set a max-width for the card.

<div class="card text-bg-dark" style="max-width: 20em;">
  <img src="..." class="card-img" alt="...">
  <div class="card-img-overlay">
    <h5 class="card-title">Card title</h5>
    <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
    <p class="card-text"><small>Last updated 3 mins ago</small></p>
  </div>
</div>

Output:

...
Card title

This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.

Last updated 3 mins ago

2. Add card title and button and style it using Bootstrap classes.

<div class="card text-bg-dark" style="max-width: 20em;">
  <img src="..." class="card-img" alt="...">
  <div class="card-img-overlay">
   <h5 class="card-title fw-bold fs-1">Lamps</h5>
    <button class="btn btn-outline-light btn-sm rounded-0 mt-2">Shop Now</button>
  </div>
</div>

Output:

...
Lamps

3. Align it to the center using text-center class. Remove the card border and add a box shadow.

<div class="card text-bg-dark border-0 shadow" style="max-width: 20em;">
  <img src="..." class="card-img" alt="...">
  <div class="card-img-overlay text-center">
    <h5 class="card-title fw-bold fs-1">Lamps</h5>
    <button class="btn btn-outline-light btn-sm rounded-0 mt-2">Shop Now</button>
  </div>
</div>

Output:

...
Lamps

4. To align it vertically and horizontally in the center, use Bootstrap’s flex classes.

<div class="card text-bg-dark border-0 shadow" style="max-width: 20em;">
    <img src="..." class="card-img" alt="...">
    <div class="card-img-overlay d-flex flex-column align-items-center justify-content-center">
        <h5 class="card-title fw-bold fs-1">Lamps</h5>
        <button class="btn btn-outline-dark btn-sm rounded-0 mt-2">Shop Now</button>
    </div>
</div>

Output:

...
Lamps


Final Output Code for Bootstrap card design:

HTML:

<div class="card text-bg-dark border-0 shadow" style="max-width: 20em;">
  <img src="..." class="card-img" alt="...">
  <div class="card-img-overlay text-center">
    <h5 class="card-title fw-bold fs-1">Lamps</h5>
    <button class="btn btn-outline-light btn-sm rounded-0 mt-2">Shop Now</button>
  </div>
</div>

Video explanation for Bootstrap card background image example:

If you have any doubts or stuck somewhere, you can reach out through Coding Yaar's Discord server.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x