Get card boxes in the middle via bootstrap [duplicate] - html

This question already has answers here:
Bootstrap Center Vertical and Horizontal Alignment
(17 answers)
Closed 2 years ago.
I have a problem. I have to cards (please see the picture )
As you can see, the two card boxes are not in the middle. I tried something, please see the code below. I hope you can help me out! Thank you in advance!
<div class="test" style="margin-left: auto; margin-right:auto; text-align: center; position: relative;">
<div class="container-fluid padding" style="margin-left: auto; margin-right:auto;">
<div class="row padding">
<div class="cold-md-4" style="margin-right: 1%; margin-left: 1%; margin-top: 1%; margin-bottom: 1%;">
<div class="card" style="width: 18rem; margin-left: 1%; ">
<img class="card-img-top" src="img\festival-tickets\ticket3.png">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</div>
</div>
<div class="cold-md-4" style="margin-right: 1%; margin-left: 1%; margin-top: 1%; margin-bottom: 1%;">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="img\festival-tickets\ticket3.png">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</div>
</div>
</div>
</div>
</div>

Just add a justify-content: center; to the parent element (that .row .padding) of the elements you want to center (the cards, in this case).
.center {
justify-content: center;
}
<div class="test" style="margin-left: auto; margin-right:auto; text-align: center; position: relative;">
<div class="container-fluid padding" style="margin-left: auto; margin-right:auto;">
<div class="row padding center">
<div class="cold-md-4" style="margin-right: 1%; margin-left: 1%; margin-top: 1%; margin-bottom: 1%;">
<div class="card" style="width: 18rem; margin-left: 1%; ">
<img class="card-img-top" src="img\festival-tickets\ticket3.png">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</div>
</div>
<div class="cold-md-4" style="margin-right: 1%; margin-left: 1%; margin-top: 1%; margin-bottom: 1%;">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="img\festival-tickets\ticket3.png">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</div>
</div>
</div>
</div>
</div>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

Related

Put a div next to an image not under

I am using Bootstrap and I have an image, and I want to have the card on the right of the image, but it is at the bottom.
I tried using display: inline-block, but that did not work. I looked at the other answers on the site and they did not work for me either, so please don't recommend those.
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<h1 style="text-align: center; font-size: 70px; ">Crabapple Lake Parc</h1>
<img src="https://th.bing.com/th/id/R.bb60507b5a1f567e6b6592f375bf5e8d?rik=FgkA6Taf%2fHwJsA&pid=ImgRaw&r=0" alt="Group Picture" style="display: block; margin-left: auto; margin-right: auto; width: 50%;">
<div class="card" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title">Have Questions?</h5>
FAQ
Contact Us
</div>
</div>
To have a card next to the image using Bootstrap, you can use the grid system. In the code below, the col-md-4 class is used to specify that the image will take up four columns out of a possible twelve, and the col-md-8 class is used to specify that the card will take up the remaining eight columns. If you find that the card is appearing below the image, it may be because the image is too wide for the column. To fix this, you can add the img-fluid class to the image to ensure that it is responsive and will fit within the column.
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<h1 style="text-align: center; font-size: 70px; ">Crabapple Lake Parc</h1>
<div class="container">
<div class="row">
<div class="col-md-4">
<img src="https://th.bing.com/th/id/R.bb60507b5a1f567e6b6592f375bf5e8d?rik=FgkA6Taf%2fHwJsA&pid=ImgRaw&r=0" class="img-fluid" alt="Group Picture">
</div>
<div class="col-md-8">
<div class="card">
<div class="card-body">
<h5 class="card-title">Have Questions?</h5>
FAQ
Contact Us
</div>
</div>
</div>
</div>
</div>
<h1 style="text-align: center; font-size: 70px;">Crabapple Lake Parc</h1>
<div class="row">
<div class="col-md-6">
<img src="https://th.bing.com/th/id/R.bb60507b5a1f567e6b6592f375bf5e8d?rik=FgkA6Taf%2fHwJsA&pid=ImgRaw&r=0" alt="Group Picture" style="display: block; margin-left: auto; margin-right: auto; width: 100%;">
</div>
<div class="col-md-6">
<div class="card" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title">Have Questions?</h5>
FAQ
Contact Us
</div>
</div>
</div>
</div>
In your parent element you can use these styles
display: flex;
justify-content: space-between;
Or in Bootstrap: d-flex and justify-content-between classes:
<div class="d-flex justify-content-between">
<h1 style="text-align: center; font-size: 70px; ">Crabapple Lake Parc</h1>
<img src="https://th.bing.com/th/id/R.bb60507b5a1f567e6b6592f375bf5e8d?rik=FgkA6Taf%2fHwJsA&pid=ImgRaw&r=0" alt="Group Picture" style="display: block; margin-left: auto; margin-right: auto; width: 50%;">
<div class="card" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title">Have Questions?</h5>
FAQ
Contact Us
</div>
</div>
</div>
WITH TITLE IN THE TOP:
<h1 style="text-align: center; font-size: 70px; ">Crabapple Lake Parc</h1>
<div class="d-flex justify-content-between">
<img src="https://th.bing.com/th/id/R.bb60507b5a1f567e6b6592f375bf5e8d?rik=FgkA6Taf%2fHwJsA&pid=ImgRaw&r=0" alt="Group Picture" style="display: block; margin-left: auto; margin-right: auto; width: 50%;">
<div class="card" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title">Have Questions?</h5>
FAQ
Contact Us
</div>
</div>
</div>
You could* use .d-inline-block if it is appropriate for your layout. You need to use it on both the img and the .card.
*I'm not necessarily recommending this, but it does what you ask.
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<h1 style="text-align: center; font-size: 70px; ">Crabapple Lake Parc</h1>
<img class="d-inline-block w-50" src="https://th.bing.com/th/id/R.bb60507b5a1f567e6b6592f375bf5e8d?rik=FgkA6Taf%2fHwJsA&pid=ImgRaw&r=0" alt="Group Picture">
<div class="card d-inline-block" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title">Have Questions?</h5>
FAQ
Contact Us
</div>
</div>

How to minimize Card spacing in Bootstraps 4

I just created 4 card using bootstraps 4.5 version but the spacing is really bad and I do not know how to reduce the spacing of card you can the image if you still confuse
.card {
width : 55%;
min-height: 100;
margin: 2%;
}
.card-img-top {
height: 150px;
object-fit: cover;
}
.card-body{
box-shadow: 0 0 20px 7px rgba(0,0,0,0.1);
}
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="card text-md-center">
<img src="Nike.jpg" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Shoes</h5>
<p class="card-text">Some quick example text</p>
Buy
</div>
</div>
</div>
<div class="col-md-4">
<div class="card text-md-center">
<img src="chevrolet.jpg" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Car</h5>
<p class="card-text">Some quick example text</p>
Buy
</div>
</div>
</div>
<div class="col-md-4">
<div class="card text-md-center">
<img src="asuslap.jpg" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Laptop</h5>
<p class="card-text">Some quick example text</p>
Buy
</div>
</div>
</div>
<div class="col-md-4">
<div class="card text-md-center">
<img src="asusphone.jpg" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Phone</h5>
<p class="card-text">Some quick example text</p>
Buy
</div>
</div>
</div>
</div>
I have searched it in google but I still not find it (How to reduce spacing of Card), maybe you can help me
If you don't problem about the width card, you can remove width : 55%; in your CSS. It would be better.
OR
You can change the value in every col-md class. The spacing the of every card is caused by that.
I added a flex-display to your .row class and justified everything in the center. Spacing looks fine to me.
.card {
width: 55%;
min-height: 100;
margin: 2%;
}
.card-img-top {
height: 150px;
object-fit: cover;
}
.card-body{
box-shadow: 0 0 20px 7px rgba(0,0,0,0.1);
}
.row {
display: flex;
justify-content: center;
}
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="card text-md-center">
<img src="Nike.jpg" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Shoes</h5>
<p class="card-text">Some quick example text</p>
Buy
</div>
</div>
</div>
<div class="col-md-4">
<div class="card text-md-center">
<img src="chevrolet.jpg" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Car</h5>
<p class="card-text">Some quick example text</p>
Buy
</div>
</div>
</div>
<div class="col-md-4">
<div class="card text-md-center">
<img src="asuslap.jpg" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Laptop</h5>
<p class="card-text">Some quick example text</p>
Buy
</div>
</div>
</div>
The Bootstrap way to do so is to dynamically adjust the column width depending on the width of the browser/screen. Do not set the width manually. Let the media query breakpoints do the job.
HTML
<div class="container">
<div class="row">
<div class="col-6 col-md-4 col-lg-3">
<div class="card text-md-center">
<img src="http://placehold.jp/320x180.png" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Shoes</h5>
<p class="card-text">Some quick example text</p>
Buy
</div>
</div>
</div>
<div class="col-6 col-md-4 col-lg-3">
<div class="card text-md-center">
<img src="http://placehold.jp/320x180.png" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Car</h5>
<p class="card-text">Some quick example text</p>
Buy
</div>
</div>
</div>
<div class="col-6 col-md-4 col-lg-3">
<div class="card text-md-center">
<img src="http://placehold.jp/320x180.png" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Laptop</h5>
<p class="card-text">Some quick example text</p>
Buy
</div>
</div>
</div>
<div class="col-6 col-md-4 col-lg-3">
<div class="card text-md-center">
<img src="http://placehold.jp/320x180.png" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Phone</h5>
<p class="card-text">Some quick example text</p>
Buy
</div>
</div>
</div>
</div>
CSS
.card {
/* width: 55%; */
min-height: 100;
margin: 2%;
}
.card-img-top {
height: 150px;
object-fit: cover;
}
.card-body {
box-shadow: 0 0 20px 7px rgba(0, 0, 0, 0.1);
}
JSFiddle demo

How to fit image according to width and height in bootstrap card?

I want to give image width and height(300px;300px;) in card:
<!-- Card Start From Here -->
<div class="card" style="width: 35rem;">
<img class="card-img-top" src="/demo/img/1.jpeg" alt="Card image cap" style="width:35rem;height:20rem;"/>
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</div>
<!-- Card Start From Here -->
The output has shrunk:
If I remove below line of code then the image will be so long but does not shrink:
style="width:35rem;height:20rem;"
I have tried:
object-fit:cover;(Check all properties like fill, scale-down)
Also tried some CSS:
<style>
.clsAutofit{
height:300px;
width:300px;
}
.clsImg{
max-width:100%;
max-height:100%;
}
</style>
<div class="clsAutofit">
<img src="/demo/img/1.jpeg" class="clsImg" />
</div>
<!-- This also not working in card -->
I also tried some properties:
<style>
img.one {
display: block;
object-fit: contain;
max-width:500px;
max-height:280px;
width: auto;
height: auto;
}
img.two {
object-fit: contain;
width: 535px;;
height: 535px;
}
.box {
width: 30%;
height: 200px;
border: 5px dashed #f7a239;
}
.containerTY {
width: 60%;
height: 500px;
}
.containerTYZ {
max-width: 100%;
}
.thumbnail {
width: 500px;
height: 400px;
}
.img4R {
width: 100%;
height: auto;
max-width: 50vw;
}
</style>
I tried but not able to make it yet.
Any idea or suggestion would be welcome.
your approach is okay.problem is,bootstrap class attributes tend to have !important.
so place your custom style.css under your bootstrap.css so it gets more priority than bs,
then use:
.my-image{
height : 300px !important;
width: 300px !important
}
bind the image with class .my-image, clear inline css styles,and check this.
.clsImg{
max-width:100%;
width: 100%;
height: auto;
object-fit:cover;
}
Using img-fluid for image and you also use w-25 w-50 w-100 for lg,md,sm etc devices
#media (min-width: 768px) {
.w-md-50{width:50% !important;}
}
#media (min-width: 992px) {
.w-lg-75{width:75% !important;}
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container">
<div class="row pt-5 w-100 mx-auto">
<!-- Card Start From Here -->
<div class="col-lg-4 col-md-6 col-sm-6 mb-4">
<div class="card p-4">
<div class="row">
<div class="col-6">
<img class="card-img-top img-fluid w-lg-75 w-md-50 w-100 text-center" src="https://i.ibb.co/Xyk1kJy/1-1.jpg" alt="Card image cap"/>
</div>
<div class="col-12">
<div class="card-body px-0 pb-0">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</div>
</div>
</div>
</div>
<!-- Card Start From Here -->
<div class="col-lg-4 col-md-6 col-sm-6 mb-4">
<div class="card p-4">
<div class="row">
<div class="col-6">
<img class="card-img-top img-fluid w-lg-75 w-md-50 w-100 text-center" src="https://i.ibb.co/Xyk1kJy/1-1.jpg" alt="Card image cap"/>
</div>
<div class="col-12">
<div class="card-body px-0 pb-0">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</div>
</div>
</div>
</div>
<!-- Card end From Here -->
<!-- Card Start From Here -->
<div class="col-lg-4 col-md-6 col-sm-6 mb-4">
<div class="card p-4">
<div class="row">
<div class="col-6">
<img class="card-img-top img-fluid w-lg-75 w-md-50 w-100 text-center" src="https://i.ibb.co/Xyk1kJy/1-1.jpg" alt="Card image cap"/>
</div>
<div class="col-12">
<div class="card-body px-0 pb-0">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</div>
</div>
</div>
</div>
<!-- Card end From Here -->
</div>
</div>

flex item being pushed out of containing div (off screen)

I am trying to build a responsive website.
and I want all of my divs to always be in the middle.
for some reason when I use flex attribute in my container the bootstrap card go offscreen:
any suggestions on how to handle it right?
Normal Screen
Normal
Moblie Screen :(
Mobile
My HTML CODE
<body>
<div class="container">
<div class="d-flex justify-content-center align-items-center">
<form action="" method="POST">
{% csrf_token %}
<div id="smain">
<h1> Lets Start</h1>
<div class="card-deck">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="{% static "/images/pc.jpg" %}" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title bulk of the
card's content.</p>
Go somewhere
</div>
</div>
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="{% static "/images/dance.png" %}" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example
text to build on the card title and makecontent.
</p>
<a href="#" class="btn btn-primary">Go
somewhere</a>
</div>
</div>
</div>
</div>
</form>
</div>
CSS
body {
background-image: url("{% static "images/unnamed1.jpg" %}");
background-size: cover;
background-repeat: no-repeat;
}
html,
body {
height: 100%;
}
.container {
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
Use margin on the children instead of justify-content: center; on the parent.
html,
body {
height: 100%;
}
.container {
height: 100%;
display: flex;
}
.container>div{
margin:auto;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">
<div class="container">
<div class="d-flex justify-content-center align-items-center">
<form action="" method="POST">
<div id="smain">
<h1> Lets Start</h1>
<div class="card-deck">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="https://picsum.photos/300/500" images="" pc.jpg "=" " %}"="" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title bulk of the card's content.</p>
Go somewhere
</div>
</div>
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="https://picsum.photos/300/500" images="" dance.png "=" " %}"="" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and makecontent.
</p>
<a href="#" class="btn btn-primary">Go
somewhere</a>
</div>
</div>
</div>
</div>
</form>
</div>
</div>

How do I make an image take a DIV's full dimension?

I've created a custom "product card" for my site, and I want the images to take the parent's full width and height, regardless of the image's dimensions. I have tried max-width min-width max-height min-height and none seem to work. I can't think of any other solution. I'm attaching an image of what I'd like and what I'm achieving now.
https://codepen.io/paulamourad/pen/MdxedG
If you want to maintain aspect ratio and don't mind cropping:
.product-img-container {
width: 100%;
height: 260px;
display: inline-block;
position: relative;
overflow:hidden; //This will crop off image portions that overflow the container
}
.card-img-top {
width: 100%; /*If you specify only width, height will be calculated automatically
and aspect ratio is maintained. Similarly, if only height is specified, width is
calculated automatically */
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
border-radius: 0px;
}
You can use the top and bottom in the .card-img-top to position the image.
It seems you are making a simple layout more complex.
You don't need to use position properties in this case. This will make simple layout more complex.
There are different scenarios how to use image more efficiently in webpages, like considering their height-width, and aspect ratio as well.
I have created a Snippet, hope so you will find it useful.
Bootstrap Cards Snippet
For dynamic product card images use the following CSS properties:
.card-img-top {
height: 100px; /* Change it based upon requirement */
object-fit: cover;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.css" rel="stylesheet"/>
<div class="container">
<h2>Bootstrap Cards Varation: </h2>
<h3>Same Aspect Ratio ―</h3>
<div class="row mb-5">
<div class="col-md-4">
<div class="card">
<img src="https://source.unsplash.com/random/1920x1080" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<img src="https://source.unsplash.com/random/1920x1080" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<img src="https://source.unsplash.com/random/1920x1080" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</div>
</div>
</div>
<!-- row -->
<h3>Same height for image (Suitable for dynamic different size images) ―</h3>
<style>
.cstm-height-card .card-img-top {
height: 100px;
object-fit: cover;
}
</style>
<div class="row mb-5 cstm-height-card">
<div class="col-md-4">
<div class="card">
<img src="https://source.unsplash.com/random/1200x900" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<img src="https://source.unsplash.com/random/1500x800" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<img src="https://source.unsplash.com/random/1400x700" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</div>
</div>
</div>
<!-- row -->
<div class="row">
<div class="col-md-6">
<div class="card mb-3">
<div class="row no-gutters align-items-center">
<div class="col-md-4">
<img src="https://source.unsplash.com/random/600x800" class="card-img" alt="...">
</div>
<div class="col-md-8">
<div class="card-body">
<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 class="text-muted">Last updated 3 mins ago</small></p>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card mb-3">
<div class="row no-gutters align-items-center">
<div class="col-md-4">
<img src="https://source.unsplash.com/random/600x800" class="card-img" alt="...">
</div>
<div class="col-md-8">
<div class="card-body">
<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 class="text-muted">Last updated 3 mins ago</small></p>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- row -->
</div>
Use a div with a background image. Set its height to 100%, background-position to center, and background size to cover.
.card-img-top {
height: 100%;
background-size: cover;
background-position: center;
}
Works in bootstrap cards, I forked your pen. https://codepen.io/Jason_B/pen/RmdoaQ