To achieve this layout, you can use the following combination of classes
position-absolute top-0 start-50 translate-middle
. This will center the element horizontally with its middle point at the top of the container. For more information, check out
https://getbootstrap.com/docs/5.2/utilities/position/#center-elements
Illustrated below is an example:
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="94f6fbfbe0e7e0e6f5e4d4a1baa6baa6">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-12 col-sm-6 col-md-4 col-lg-3 mt-5">
<div class="card mt-5 pt-5">
<img src="https://www.fillmurray.com/200/200" class="rounded-circle w-50 position-absolute top-0 start-50 translate-middle" alt="">
<div class="card-body text-center pt-5">
<h5 class="card-title">Card title</h5>
<h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>
</div>
</div>
</div>
<div class="col-12 col-sm-6 col-md-4 col-lg-3 mt-5">
<div class="card mt-5 pt-5">
<img src="https://www.fillmurray.com/199/200" class="rounded-circle w-50 position-absolute top-0 start-50 translate-middle" alt="">
<div class="card-body text-center pt-5">
<h5 class="card-title">Card title</h5>
<h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>
</div>
</div>
</div>
<div class="col-12 col-sm-6 col-md-4 col-lg-3 mt-5">
<div class="card mt-5 pt-5">
<img src="https://www.fillmurray.com/200/198" class="rounded-circle w-50 position-absolute top-0 start-50 translate-middle" alt="">
<div class="card-body text-center pt-5">
<h5 class="card-title">Card title</h5>
<h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>
</div>
</div>
</div>
<div class="col-12 col-sm-6 col-md-4 col-lg-3 mt-5">
<div class="card mt-5 pt-5">
<img src="https://www.fillmurray.com/200/199" class="rounded-circle w-50 position-absolute top-0 start-50 translate-middle" alt="">
<div class="card-body text-center pt-5">
<h5 class="card-title">Card title</h5>
<h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>
</div>
</div>
</div>
</div>
</div>
The inclusion of margin and padding classes such as .col
, .card
, and .card-body
is crucial to prevent image overlap or overflow outside the container boundaries.