I'm working on a Bootstrap project where I display a card with an image on the left and text on the right. I want the image to look smaller, like a thumbnail, and I also want to reduce the overall height of the card to make it more compact. However, the image should still fit nicely in its container without being distorted.
Here's my current code:
<div class="container my-4">
<div class="row">
<!-- Card 1 -->
<div class="col-12 mb-4">
<div class="card shadow d-flex flex-row h-100">
<!-- Image container -->
<div class="col-4 p-0">
<div class="ratio ratio-1x1">
<img src="path-to-image.jpg" class="img-fluid rounded-start" alt="Property 1"
style="object-fit: cover;">
</div>
</div>
<div class="card-body d-flex flex-column col-8">
<h5 class="card-title">Beautiful Duplex for Sale</h5>
<p class="card-text text-success fw-bold">USD 800,000.00</p>
<p class="card-text"><i class="fa-solid fa-location-dot"></i> Lima, Peru</p>
<p class="card-text">This furnished duplex with 3 bedrooms in San Isidro offers a great view of the golf course. Perfect for you!</p>
<div class="hstack gap-3 card-data d-flex justify-content-around mb-3">
<p class="m-0"><i class="fa-solid fa-bed"></i> 3</p>
<p class="m-0"><i class="fa-solid fa-bath"></i> 3</p>
<p class="m-0"><i class="fa-solid fa-chart-area"></i> 500.00 m2</p>
<p class="m-0"><i class="fa-solid fa-house"></i> 350.00 m2</p>
</div>
<div class="d-grid mt-auto">
<button class="btn btn-outline-success" type="button">More Info</button>
</div>
</div>
</div>
</div>
</div>
</div>
Currently:
The image is displayed at a fixed size, but it's too large for the layout. I want the image to look like a thumbnail (smaller and proportional to the card). The height of the card should shrink accordingly. Expected result:
The card should have a reduced height. The image should scale proportionally within its container, like a thumbnail, without distorting or cutting off too much content. What I've tried:
Using object-fit: cover with the ratio class. Setting a fixed height for the card using inline styles (e.g., style="height: 250px;"). Adding classes like img-thumbnail and adjusting margins/paddings, but this affects the overall layout. Question: How can I properly resize the image to look like a thumbnail and reduce the card height while maintaining responsiveness? Is there a Bootstrap-specific approach or a CSS adjustment I should make?
I'm working on a Bootstrap project where I display a card with an image on the left and text on the right. I want the image to look smaller, like a thumbnail, and I also want to reduce the overall height of the card to make it more compact. However, the image should still fit nicely in its container without being distorted.
Here's my current code:
<div class="container my-4">
<div class="row">
<!-- Card 1 -->
<div class="col-12 mb-4">
<div class="card shadow d-flex flex-row h-100">
<!-- Image container -->
<div class="col-4 p-0">
<div class="ratio ratio-1x1">
<img src="path-to-image.jpg" class="img-fluid rounded-start" alt="Property 1"
style="object-fit: cover;">
</div>
</div>
<div class="card-body d-flex flex-column col-8">
<h5 class="card-title">Beautiful Duplex for Sale</h5>
<p class="card-text text-success fw-bold">USD 800,000.00</p>
<p class="card-text"><i class="fa-solid fa-location-dot"></i> Lima, Peru</p>
<p class="card-text">This furnished duplex with 3 bedrooms in San Isidro offers a great view of the golf course. Perfect for you!</p>
<div class="hstack gap-3 card-data d-flex justify-content-around mb-3">
<p class="m-0"><i class="fa-solid fa-bed"></i> 3</p>
<p class="m-0"><i class="fa-solid fa-bath"></i> 3</p>
<p class="m-0"><i class="fa-solid fa-chart-area"></i> 500.00 m2</p>
<p class="m-0"><i class="fa-solid fa-house"></i> 350.00 m2</p>
</div>
<div class="d-grid mt-auto">
<button class="btn btn-outline-success" type="button">More Info</button>
</div>
</div>
</div>
</div>
</div>
</div>
Currently:
The image is displayed at a fixed size, but it's too large for the layout. I want the image to look like a thumbnail (smaller and proportional to the card). The height of the card should shrink accordingly. Expected result:
The card should have a reduced height. The image should scale proportionally within its container, like a thumbnail, without distorting or cutting off too much content. What I've tried:
Using object-fit: cover with the ratio class. Setting a fixed height for the card using inline styles (e.g., style="height: 250px;"). Adding classes like img-thumbnail and adjusting margins/paddings, but this affects the overall layout. Question: How can I properly resize the image to look like a thumbnail and reduce the card height while maintaining responsiveness? Is there a Bootstrap-specific approach or a CSS adjustment I should make?
Share Improve this question asked Jan 18 at 15:32 Aaron MasAaron Mas 791 gold badge1 silver badge9 bronze badges 01 Answer
Reset to default 0When you create the card you set it's size, in this case you set the size with the class h-100
to make the card height smaller change its class from h-100
to h-75
, for example: <div class=“card shadow d-flex flex-row h-75”>
or according to your needs.
Here is the corrected code (I also add .img-fluid{height: max-content;}
and .card{overflow: auto;}
so that the content does not go out of bounds):
Codepen
.img-fluid{
height: max-content;
}.card{
overflow: auto;
}
<link href="https://cdnjs.cloudflare/ajax/libs/bootstrap/5.0.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container my-4">
<div class="row">
<!-- Card 1 -->
<div class="col-12 mb-4">
<div class="card shadow d-flex flex-row h-75">
<!-- Image container -->
<div class="col-4 p-0">
<div class="ratio ratio-1x1">
<img src="https://external-content.duckduckgo/iu/?u=https%3A%2F%2F3.bp.blogspot%2F-JxYjZjRXIh4%2FVDWJoJPtYuI%2FAAAAAAACVDM%2FC9r2wraqtlQ%2Fs1600%2Fpaisajes%252Bnaturales%252Bfotos%252Bnuevas%252B(10).jpg&f=1&nofb=1&ipt=2a4c2e949bfec7539160797876d8f861cc9a4b282df2fdb934835419f6c1ef9e&ipo=images" class="img-fluid rounded-start" alt="Property 1"
style="object-fit: cover;">
</div>
</div>
<div class="card-body d-flex flex-column col-8">
<h5 class="card-title">Beautiful Duplex for Sale</h5>
<p class="card-text text-success fw-bold">USD 800,000.00</p>
<p class="card-text"><i class="fa-solid fa-location-dot"></i> Lima, Peru</p>
<p class="card-text">This furnished duplex with 3 bedrooms in San Isidro offers a great view of the golf course. Perfect for you!</p>
<div class="hstack gap-3 card-data d-flex justify-content-around mb-3">
<p class="m-0"><i class="fa-solid fa-bed"></i> 3</p>
<p class="m-0"><i class="fa-solid fa-bath"></i> 3</p>
<p class="m-0"><i class="fa-solid fa-chart-area"></i> 500.00 m2</p>
<p class="m-0"><i class="fa-solid fa-house"></i> 350.00 m2</p>
</div>
<div class="d-grid mt-auto">
<button class="btn btn-outline-success" type="button">More Info</button>
</div>
</div>
</div>
</div>
</div>
</div>