Here is an example of the grid system. You need to create a row to hold all of the sections. Then inside the row, create 2 columns, left and right. On the right column, create 2 rows.
So the structure should be like this:
- row
- column
- column
- row
- row
<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col" style="padding:100px; background:red;">
1
</div>
<div class="col">
<div class="row" style="padding:100px; background:blue;">
2
</div>
<div class="row" style="padding:100px; background:gray;">
3
</div>
</div>
</div>
</div>
</body>
</html>
Answer from Regn on Stack OverflowVideos
You can achieve this with card columns. JSFiddle here:
<div class="container-fluid pt-3">
<div class="card-columns">
<div class="card">
<img class="card-img-top" style="width:100%; height: 200px;"/>
</div>
<div class="card">
<img class="card-img-top" style="width:100%; height: 500px;"/>
</div>
<div class="card">
<img class="card-img-top" style="width:100%; height: 300px;"/>
</div>
<div class="card">
<img class="card-img-top" style="width:100%; height: 400px;"/>
</div>
<div class="card">
<img class="card-img-top" style="width:100%; height: 400px;"/>
</div>
<div class="card">
<img class="card-img-top" style="width:100%; height: 300px;"/>
</div>
<div class="card">
<img class="card-img-top" style="width:100%; height: 500px;"/>
</div>
<div class="card">
<img class="card-img-top" style="width:100%; height: 200px;"/>
</div>
<div class="card">
<img class="card-img-top" style="width:100%; height: 200px;"/>
</div>
<div class="card">
<img class="card-img-top" style="width:100%; height: 500px;"/>
</div>
<div class="card">
<img class="card-img-top" style="width:100%; height: 300px;"/>
</div>
<div class="card">
<img class="card-img-top" style="width:100%; height: 400px;"/>
</div>
</div>
</div>
depending on you requirement, you need to replace col-3 with col-sm-3 or col-md-3, etc:
img
{
width: 100%;
margin: 10px 0px;
}
<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="row">
<div class="col-3">
<img src="https://www.w3schools.com/w3images/nature.jpg" alt="Lights" >
<img src="https://www.w3schools.com/w3images/falls2.jpg" alt="Lights" >
<img src="https://www.w3schools.com//w3images/wedding.jpg"alt="Lights" >
</div>
<div class="col-3">
<img src="https://www.w3schools.com/w3images/rocks.jpg" alt="Lights" >
<img src="https://www.w3schools.com/w3images/fjords.jpg" alt="Lights" >
</div>
<div class="col-3">
<img src="https://www.w3schools.com/w3images/fjords.jpg" alt="Lights" >
<img src="https://www.w3schools.com/w3images/lights.jpg" alt="Lights" >
<img src="https://www.w3schools.com//w3images/wedding.jpg"alt="Lights" >
</div>
<div class="col-3">
<img src="https://www.w3schools.com/w3images/nature.jpg" alt="Lights" >
<img src="https://www.w3schools.com//w3images/rocks.jpg" alt="Lights" >
</div>
</div>
I think the property you're looking for is object-fit
img {
width: 200px; /* You can set the dimensions to whatever you want */
height: 200px;
object-fit: cover;
}
The object-fit property works similarly to how you would using background-size: cover on a background image to make it fill the page without stretching. This way, you can define a width in a rule that all images will follow to ensure that they are the same size without distorting your picture.
Other values you can use with this property includes:
fill- stretch the image.contain- preserve the aspect ratio of the image.cover- Fill the height and width of the box.none- Keep the original size.scale-down- compare the differences between none and contain to find the smallest object size.
object-fit | CSS-Tricks
Add the css class img-responsive to every image.
Instead of using d-flex class use row row-cols-1 row-cols-sm-2 row-cols-md-4 or you can refer this https://getbootstrap.com/docs/4.5/layout/grid/#row-columns Also to make things easy you can use card grid https://getbootstrap.com/docs/4.5/components/card/#grid-cards it will automatically handle the responsiveness of the layout and you can make tweaks accordingly.
try something like this
I added media query, used flexbox and changed the max width and height of images
HTML
`
<div class="img-wrapper-20">
<img src="https://informnutrition.com/wp-content/uploads/2019/03/Super-booster-Sheep-400x300.png" class="img-fluid img-thumbnail shadow img-dimension" alt="Sheep 11">
<p class="galp">Some Text</p>
</div>
<div class="img-wrapper-20">
<img src="https://informnutrition.com/wp-content/uploads/2019/03/Super-booster-Sheep-400x300.png" class="img-fluid img-thumbnail shadow img-dimension" alt="Sheep 11">
<p class="galp">Some Text</p>
</div>
<div class="img-wrapper-20">
<img src="https://informnutrition.com/wp-content/uploads/2019/03/Super-booster-Sheep-400x300.png" class="img-fluid img-thumbnail shadow img-dimension" alt="Sheep 11">
<p class="galp">Some Text</p>
</div>
<div class="img-wrapper-20">
<img src="https://informnutrition.com/wp-content/uploads/2019/03/Super-booster-Sheep-400x300.png" class="img-fluid img-thumbnail shadow img-dimension" alt="Sheep 11">
<p class="galp">Some Text</p>
</div>
<div class="img-wrapper-20">
<img src="https://informnutrition.com/wp-content/uploads/2019/03/Super-booster-Sheep-400x300.png" class="img-fluid img-thumbnail shadow img-dimension" alt="Sheep 11">
<p class="galp">Some Text</p>
</div>
</div>
</div>`
CSS:
.container {
padding: 5rem 0rem;
}
.img-wrapper-20 {
max-width: 20%;
margin: 0rem 1.5rem 0rem 0rem;
}
.img-wrapper-20 img:hover {
transform: scale(1.08);
}
.galp {
margin-top: 20px;
text-align: center;
font-size: 20px;
font-weight: 700;
color: black;
}
.img-dimension {
max-width:100%;
}
@media screen and (max-width: 1000px) {
.d-flex {
display:flex;
flex-direction: column;
overflow: auto;
}
.img-wrapper-20 {
max-width: 80%;
margin: 0rem 1.5rem 0rem 0rem;
}
}
@media screen and (min-width: 1000px) {
.d-flex {
display: flex;
flex-direction: row;
overflow: auto;
}
}