To achieve what you're looking for, you need to add a gap or margin between the horizontal cards and ensure they stack vertically on smaller screens. Bootstrap 5 offers utility classes to help with spacing and responsive design.
Here’s how you can modify your code to include a gap/margin between the cards and stack them vertically on mobile screens:
<div class="container d-flex flex-column flex-md-row gap-3 mt-4 p-4">
<div class="card mb-3" style="max-width:540px;">
<div class="row g-0">
<div class="col-md-6">
<img src="https://media.geeksforgeeks.org/wp-content/cdn-uploads/20190710102234/download3.png"
class="img-fluid rounded-start" alt="...">
</div>
<div class="col-md-6">
<div class="card-body">
<h5 class="card-title">Data Structures</h5>
<p class="card-text">
A data structure is a storage that is
used to store and organize data.
</p>
<p class="card-text">
<small class="text-muted">Last updated now</small>
</p>
</div>
</div>
</div>
</div>
<div class="card mb-3" style="max-width:540px;">
<div class="row g-0">
<div class="col-md-6">
<img src="https://media.geeksforgeeks.org/wp-content/cdn-uploads/gfg_200x200-min.png"
class="img-fluid rounded-start" alt="...">
</div>
<div class="col-md-6">
<div class="card-body">
<h5 class="card-title">Algorithms</h5>
<p class="card-text">
Algorithm refers to a sequence of
finite steps to solve a particular problem.
</p>
<p class="card-text">
<small class="text-muted">Last updated now</small>
</p>
</div>
</div>
</div>
</div>
</div>
Key Changes:
-
Flexbox Layouts: Added flex-column and flex-md-row to the d-flex class. This makes the cards stack vertically in a column by default but switch to a row layout on medium screens (768px) and larger.
-
Gap Utility: Added gap-3 to provide a gap between the cards. You can adjust the number in gap-3 to increase or decrease the spacing as needed (Bootstrap uses 0 to 5 and auto for gap utility).
By implementing these changes, your cards will have a visible gap/margin between them and will stack on smaller screens. Bootstrap's responsive grid and utility classes make such adjustments straightforward.