Flex Contents wont Align in a Row Horizontally (Bootstrap 5) - html

My Images seems to be not aligning in a Horizontal Row, I Tried every method but not working :(
Output:
.img-size-square {
width: 100%;
height: auto;
max-width: 400px !important;
max-height: 400px !important;
}
.container-for-hover {
position: relative;
width: 50%;
}
.image-for-hover {
display: block;
width: 100%;
height: auto;
}
.overlay-for-hover {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: #6633ff;
}
.container-for-hover:hover .overlay-for-hover {
opacity: 1;
}
.text-for-hover {
color: white;
font-weight: bold;
font-size: 20px;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<div class="row">
<div class="row">
<div class="d-flex col-12">
<div class="mx-auto">
<div class="container-for-hover img-size-square mb-2">
<img class="image-for-hover" src="http://jazzfu.000webhostapp.com/upload/placeholder-sq.webp">
<div class="overlay-for-hover">
<div class="text-for-hover">Some Content Here 1, Row 1</div>
</div>
</div>
<div class="container-for-hover img-size-square mb-2">
<img class="image-for-hover" src="http://jazzfu.000webhostapp.com/upload/placeholder-sq.webp">
<div class="overlay-for-hover">
<div class="text-for-hover">Some Content Here 2, Row 1</div>
</div>
</div>
<div class="container-for-hover img-size-square mb-2">
<img class="image-for-hover" src="http://jazzfu.000webhostapp.com/upload/placeholder-sq.webp">
<div class="overlay-for-hover">
<div class="text-for-hover">Some Content Here 3, Row 1</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="d-flex col-12">
<div class="mx-auto">
<div class="container-for-hover img-size-square mb-2">
<img class="image-for-hover" src="http://jazzfu.000webhostapp.com/upload/placeholder-sq.webp">
<div class="overlay-for-hover">
<div class="text-for-hover">Some Content Here 1, Row 2</div>
</div>
</div>
<div class="container-for-hover img-size-square mb-2">
<img class="image-for-hover" src="http://jazzfu.000webhostapp.com/upload/placeholder-sq.webp">
<div class="overlay-for-hover">
<div class="text-for-hover">Some Content Here 2, Row 2</div>
</div>
</div>
<div class="container-for-hover img-size-square mb-2">
<img class="image-for-hover" src="http://jazzfu.000webhostapp.com/upload/placeholder-sq.webp">
<div class="overlay-for-hover">
<div class="text-for-hover">Some Content Here 3, Row 2</div>
</div>
</div>
</div>
</div>
</div>
</div>
What I Tried:
I Tried everything on the Official Docs and on here -> W3 BS5 Docs, I Tried also flex-row, I'm also new to Web Developing Field.
Goal:
The container-for-image Div(s) should be Placed in a Horizontal Row in each row class div

just use flex on class mx-auto
.img-size-square {
width: 100%;
height: auto;
max-width: 400px !important;
max-height: 400px !important;
}
.container-for-hover {
position: relative;
width: 50%;
}
.image-for-hover {
display: block;
width: 100%;
height: auto;
}
.overlay-for-hover {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: #6633ff;
}
.container-for-hover:hover .overlay-for-hover {
opacity: 1;
}
.text-for-hover {
color: white;
font-weight: bold;
font-size: 20px;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}
.mx-auto{
display:flex;
margin:0 auto;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<div class="row">
<div class="row">
<div class="d-flex col-12">
<div class="mx-auto">
<div class="container-for-hover img-size-square mb-2">
<img class="image-for-hover" src="http://jazzfu.000webhostapp.com/upload/placeholder-sq.webp">
<div class="overlay-for-hover">
<div class="text-for-hover">Some Content Here 1, Row 1</div>
</div>
</div>
<div class="container-for-hover img-size-square mb-2">
<img class="image-for-hover" src="http://jazzfu.000webhostapp.com/upload/placeholder-sq.webp">
<div class="overlay-for-hover">
<div class="text-for-hover">Some Content Here 2, Row 1</div>
</div>
</div>
<div class="container-for-hover img-size-square mb-2">
<img class="image-for-hover" src="http://jazzfu.000webhostapp.com/upload/placeholder-sq.webp">
<div class="overlay-for-hover">
<div class="text-for-hover">Some Content Here 3, Row 1</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="d-flex col-12">
<div class="mx-auto">
<div class="container-for-hover img-size-square mb-2">
<img class="image-for-hover" src="http://jazzfu.000webhostapp.com/upload/placeholder-sq.webp">
<div class="overlay-for-hover">
<div class="text-for-hover">Some Content Here 1, Row 2</div>
</div>
</div>
<div class="container-for-hover img-size-square mb-2">
<img class="image-for-hover" src="http://jazzfu.000webhostapp.com/upload/placeholder-sq.webp">
<div class="overlay-for-hover">
<div class="text-for-hover">Some Content Here 2, Row 2</div>
</div>
</div>
<div class="container-for-hover img-size-square mb-2">
<img class="image-for-hover" src="http://jazzfu.000webhostapp.com/upload/placeholder-sq.webp">
<div class="overlay-for-hover">
<div class="text-for-hover">Some Content Here 3, Row 2</div>
</div>
</div>
</div>
</div>
</div>
</div>

You need to have the 3 children as direct children of the d-flex container, since that is the flex container. The way you have it, d-flex is trying to put only mx-auto into a row (resulting in a row of 1 div).
<div class="row">
<div class="row">
<div class="d-flex col-12 mx-auto">
<div class="container-for-hover img-size-square mb-2">
...
</div>
<div class="container-for-hover img-size-square mb-2">
...
</div>
<div class="container-for-hover img-size-square mb-2">
...
</div>
</div>
</div>
</div>

Related

Responsive design (breakpoints) - Put everything in one column

I divided a page into two columns. When I reduce the screen, is there any way to put everything in just one column?
At this moment, when I reduce the screen, the width of the cards decreases (as shown in the image). Is there a way to put all the cards in just one column (on mobile) in order to keep the width at 100%?
Is there a way to put everything in just one column and with a margin top between the elements?
Thanks.
Stackblitz - DEMO
Code
<div style="width: 100%; height: 100%; overflow-y: scroll; overflow-x: hidden;">
<div style="width: 100%; height: 85%">
<div class="modal-body row" style="overflow: auto; margin-top: 135px; height: 100%;">
<div class="col-md-6">
<div style="height: 700px;">
<div class="container">
</div>
<div class="row">
<div class="Upcard">
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="row" style="height: 100%;">
<div class="col-6">
<div class="card cardBig" style="margin-left: 16px; margin-right: 16px; line-height: 1;">
<div class="card-header header">
<h1> It </h1>
</div>
<div class="card-body">
</div>
</div>
</div>
<div class="col-6">
<div class="card" style="margin-left: 8px; margin-right: 16px; line-height: 1;">
<div class="card-header header">
<h1> data </h1>
</div>
<div class="card-body">
</div>
</div>
<div class="card card-small" style="margin-left: 8px; margin-right: 16px; margin-top: 16px;">
<div class="card-header header">
<h1> T </h1>
</div>
<div class="card-body" style="overflow-y: auto; overflow-x: hidden;">
</div>
</div>
<div class="card card-small" style="margin-left: 8px; margin-right: 16px; margin-top: 16px;">
<div class="card-header header">
<h1> Att </h1>
</div>
<div class="card-body att" style="overflow-x: hidden; overflow-y: auto;">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Please try this snippet.
.card {
width: 100%;
height: 50%;
margin-bottom: 16px;
background: red 0% 0% no-repeat padding-box;
box-shadow: 0px 3px 20px #BCBCCB47;
border-radius: 8px;
opacity: 1;
border: none;
}
.cardBig {
height: calc(100% - 16px);
}
.card-small {
height: 23%;
}
/* ---------------------------UPLOAD----------------------------------- */
.container {
width: 100%;
height: 100%;
padding: 2rem;
text-align: center;
border: dashed 4px blue;
position: relative;
margin: 0 auto;
border-radius: 16px;
display: flex;
justify-content: center;
align-items: center;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div style="width: 100%; height: 100%; overflow-y: scroll; overflow-x: hidden;">
<div style="width: 100%; height: 85%">
<div class="modal-body row" style="overflow: auto; margin-top: 135px; height: 100%;">
<div class="col-md-6 col-sm-12">
<div style="height: 700px;">
<div class="container">
</div>
<div class="row">
<div class="Upcard">
</div>
</div>
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="row" style="height: 100%;">
<div class="col-md-6 col-sm-12">
<div class="card cardBig">
<div class="card-header header">
<h1> It </h1>
</div>
<div class="card-body">
</div>
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="card">
<div class="card-header header">
<h1> data </h1>
</div>
<div class="card-body">
</div>
</div>
<div class="card card-small">
<div class="card-header header">
<h1> T </h1>
</div>
<div class="card-body" style="overflow-y: auto; overflow-x: hidden;">
</div>
</div>
<div class="card card-small">
<div class="card-header header">
<h1> Att </h1>
</div>
<div class="card-body att" style="overflow-x: hidden; overflow-y: auto;">
<p>asdasdasdasdasdasdasdas</p>
<p>asdasdasdasdasdasdasdas</p>
<p>asdasdasdasdasdasdasdas</p>
<p>asdasdasdasdasdasdasdas</p>
<p>asdasdasdasdasdasdasdas</p>
<p>asdasdasdasdasdasdasdas</p>
<p>asdasdasdasdasdasdasdas</p>
<p>asdasdasdasdasdasdasdas</p>
<p>asdasdasdasdasdasdasdas</p>
<p>asdasdasdasdasdasdasdas</p>
<p>asdasdasdasdasdasdasdas</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

Divs disappear when using inline-block

Trying to create a responsive flip-card gallery using a code I came across here. Everything works great except for when I try to align the flip-cards next to each other (trying to create three cards per row) then they just disappear. I've tried using display: inline-block and a flex-grid, but can't figure out where i'm going wrong.
Thank you!
Here's the intial code:
HTML
<div class="container">
<div class="card-container">
<div class="row">
<div class="col">
<div class="flip-container">
<div class="flipper">
<div class="front">
<div class="inner"><img src="image1.jpg" style="height: 100%;"></div>
</div>
<div class="back">
<div class="inner">Back</div>
</div>
</div>
</div>
</div>
</div>
<div class="card-container">
<div class="row">
<div class="col">
<div class="flip-container">
<div class="flipper">
<div class="front">
<div class="inner"><img src="metalcard.jpg" style="height: 100%;"></div>
</div>
<div class="back">
<div class="inner">Back</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="card-container">
<div class="row">
<div class="col">
<div class="flip-container">
<div class="flipper">
<div class="front">
<div class="inner"><img src="image3.jpg" style="height: 100%;"></div>
</div>
<div class="back">
<div class="inner">Back</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
CSS:
.container {
margin: 0 auto;
max-width: 1200px;
padding: 0 1rem;
display: inline-block;
}
.card-container{
width: 25%; /* Adjust the target width*/
}
.flip-container {
position: relative;
perspective: 1000px;
}
/* flip the pane when hovered */
.flip-container:hover .flipper, .flip-container.hover .flipper {
transform: rotateY(180deg);
}
.flip-container, .front, {
width: 100%;
height: 170px;
}
.flip-container,.back {
height: 190px;
width: 100%;
}
.flipper {
transition: 0.9s;
transform-style: preserve-3d;
position: relative;
}
.front, .back {
backface-visibility: hidden;
position: absolute;
top: 0;
left: 0;
}
.front {
background: rgba(0,0,0,0.05);
z-index: 2;
/* for firefox 31 */
transform: rotateY(0deg);
}
/* back, initially hidden pane */
.back {
background: #00ccff;
transform: rotateY(180deg);
}
I tried your code in a jsfiddle and they were some parts of the html code missing and i fix the class .container and .card-container
Here you go
HTML
<div class="container">
<div class="card-container">
<div class="row">
<div class="col">
<div class="flip-container">
<div class="flipper">
<div class="front">
<div class="inner"><img src="image1.jpg" style="height: 100%;"> </div>
</div>
<div class="back">
<div class="inner">Back</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="card-container">
<div class="row">
<div class="col">
<div class="flip-container">
<div class="flipper">
<div class="front">
<div class="inner"><img src="metalcard.jpg" style="height: 100%;"></div>
</div>
<div class="back">
<div class="inner">Back</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="card-container">
<div class="row">
<div class="col">
<div class="flip-container">
<div class="flipper">
<div class="front">
<div class="inner"><img src="image3.jpg" style="height: 100%;"></div>
</div>
<div class="back">
<div class="inner">Back</div>
</div>
</div>
</div>
</div>
</div>
</div>
CSS
.container {
width: 100%;
}
.card-container{
width: 25%; /* Adjust the target width*/
display: inline-block;
}

Inexplicable gap in a bootstrap row/column

I have been trying to code a simple gallery in Bootstrap, however, there is an unnecessary gap that keeps on appearing again and again on the right side of the column. I am unable to understand the cause of this gap.
Here is the HTML Code:
<div class="row" id="r2">
<div class="col-md-12" id="heading">
<h1>| PROJECTS |</h1>
</div>
</div>
<div class="row no-gutters">
<div class="col-xs-12 col-sm-6 col-md-4">
<img src="img/9.jpg" style='width: 100%; object-fit: contain'>
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 left">
<img src="img/10.jpg" style='width: 100%; object-fit: contain'>
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 left">
<img src="img/11.jpg" style='width: 100%; object-fit: contain'>
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
<div class="clearfix"></div>
<div class="col-xs-12 col-sm-6 col-md-4 left">
<img src="img/8.jpg" style='width: 100%; object-fit: contain'>
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 left">
<img src="img/7.jpg" style='width: 100%; object-fit: contain'>
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 left">
<img src="img/8.jpg" style='width: 100%; object-fit: contain'>
<div class="overlay">
<div class="text">View More..</div>
</div>
</div>
<div class="clearfix"></div>
</div>
<div class="clear"></div>
Here is a screenshot of the webpage showing the gap:Right Side Gap
The CSS Code :
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0px;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: black;
}
.overlay:hover {
opacity: 0.8;
}
.text {
color: white;
font-size: 20px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
text-align: center;
}
#r2{
background:#2952a3;
margin:0;
}
Any sort of help would be really appreciated!

How can I reduce the horizontal space between col-md-4 divs?

HTML
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="content">1x1</div>
</div>
<div class="col-md-4">
<div class="content">1x2</div>
</div>
<div class="col-md-4">
<div class="content">1x3</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="content">2x1</div>
</div>
<div class="col-md-4">
<div class="content">2x2</div>
</div>
<div class="col-md-4">
<div class="content">2x3</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="content">3x1</div>
</div>
<div class="col-md-4">
<div class="content">3x2</div>
</div>
<div class="col-md-4">
<div class="content">3x3</div>
</div>
</div>
</div>
CSS
.container {
text-align: center;
display: flex;
flex-direction: column;
}
.content {
background-color: #1A1919;
color: white;
height: 400px;
width: 300px;
}
.row{
padding: 5px;
}
I have managed to make vertical spaces between the columns by adding padding to the rows. But now the horizontal spaces between the contents are ways too much. How can I configure the spacing between them?
That large horizontal space is because of the fixed width of the content class if you remove that, you'll see it grow.
You can set the width of the content in % or add a margin to the content class.
.container {
text-align: center;
}
.content {
background-color: #1A1919;
color: white;
height: 400px;
}
.row{
padding:15px;
}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col-md-4 col4">
<div class="content">1x1</div>
</div>
<div class="col-md-4 col4">
<div class="content">1x2</div>
</div>
<div class="col-md-4 col4">
<div class="content">1x3</div>
</div>
</div>
<div class="row ">
<div class="col-md-4 col4">
<div class="content">2x1</div>
</div>
<div class="col-md-4 col4">
<div class="content">2x2</div>
</div>
<div class="col-md-4 col4">
<div class="content">2x3</div>
</div>
</div>
<div class="row col4 col4">
<div class="col-md-4 col4">
<div class="content">3x1</div>
</div>
<div class="col-md-4 col4">
<div class="content">3x2</div>
</div>
<div class="col-md-4">
<div class="content">3x3</div>
</div>
</div>
</div>
CSS Grid to achieve that layout you desire:
.grid-container {
display: grid;
grid-template-columns: auto auto auto;
grid-gap: 5px;
position:absolute;
left:50%;
transform:translateX(-50%);
width:80%;
}
.item {
background-color: gray;
text-align: center;
font-size: 30px;
min-height:100px;
max-width: 350px;
}
<div class="grid-container">
<div class="item">1x1</div>
<div class="item">1x2</div>
<div class="item">1x3</div>
<div class="item">2x1</div>
<div class="item">2x2</div>
<div class="item">2x3</div>
<div class="item">3x1</div>
<div class="item">3x2</div>
<div class="item">3x3</div>
</div>
Using flexbox:
.flex-container {
display: flex;
/*Generates a flexbox layout with default flex direction as row */
width: 100%;
/* Not really required */
align-items: center;
/*Aligns contents vertically */
justify-content: center;
/*Aligns contents horizontally */
text-align: center;
/*Aligns further text in the center */
}
.item {
background-color: gray;
text-align: center;
font-size: 30px;
min-height: 400px;
width: 300px;
margin: 5px;
}
<div class="flex-container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
<div class="flex-container">
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
</div>
<div class="flex-container">
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
</div>
Use float:left; with class content as below:
.container {
text-align: center;
display: flex;
flex-direction: column;
}
.content {
float: left;
background-color: #1A1919;
color: white;
height: 400px;
width: 300px;
}
.row{
padding: 5px;
}
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="content">1x1</div>
</div>
<div class="col-md-4">
<div class="content">1x2</div>
</div>
<div class="col-md-4">
<div class="content">1x3</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="content">2x1</div>
</div>
<div class="col-md-4">
<div class="content">2x2</div>
</div>
<div class="col-md-4">
<div class="content">2x3</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="content">3x1</div>
</div>
<div class="col-md-4">
<div class="content">3x2</div>
</div>
<div class="col-md-4">
<div class="content">3x3</div>
</div>
</div>
</div>
If I'm reading your request correctly, you are just asking how to make it look like the boxes are in the center of the page, and they are evenly spaced. see if this is what you're looking for:
.container {
text-align: center;
display: flex;
flex-direction: column;
}
.content {
background-color: #1A1919;
color: white;
height: 400px;
width: 300px;
}
.col-md-4 {
margin: 5px -10px 0px -4px;;
}
play with the numbers until you get the desired location.
Though I would strongly suggest that you add your own class in addition to col-md-4 to the boxes, which will prevent this new setting to col-md-4 from affecting any future use of this bootstrap class.
in other words . . .
CSS:
.container {
text-align: center;
display: flex;
flex-direction: column;
}
.content {
background-color: #1A1919;
color: white;
height: 400px;
width: 300px;
}
.box-move {
margin: 5px -10px 0px -4px;;
}
and HTML:
<div class="container">
<div class="row">
<div class="col-md-4 box-move">
<div class="content">1x1</div>
</div>
<div class="col-md-4 box-move">
<div class="content">1x2</div>
</div>
<div class="col-md-4 box-move">
<div class="content">1x3</div>
</div>
</div>
<div class="row">
<div class="col-md-4 box-move">
<div class="content">2x1</div>
</div>
<div class="col-md-4 box-move">
<div class="content">2x2</div>
</div>
<div class="col-md-4 box-move">
<div class="content">2x3</div>
</div>
</div>
<div class="row">
<div class="col-md-4 box-move">
<div class="content">3x1</div>
</div>
<div class="col-md-4 box-move">
<div class="content">3x2</div>
</div>
<div class="col-md-4 box-move">
<div class="content">3x3</div>
</div>
</div>
</div>
You can remove a lot of the stuff there and simplify it to make it responsive width a set margin:
.contents {
background-color: black;
color: white;
height: 500px;
margin: 20px 0px;
}
<div class="container-fluid text-center">
<div class="row">
<div class="col-md-4">
<div class="contents">1x1</div>
</div>
<div class="col-md-4">
<div class="contents">1x2</div>
</div>
<div class="col-md-4">
<div class="contents">1x3</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="contents">2x1</div>
</div>
<div class="col-md-4">
<div class="contents">2x2</div>
</div>
<div class="col-md-4">
<div class="contents">2x3</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="contents">3x1</div>
</div>
<div class="col-md-4">
<div class="contents">3x2</div>
</div>
<div class="col-md-4">
<div class="contents">3x3</div>
</div>
</div>
</div>
</div>

Adjacent div overlap on top of each other using CSS transform property and transition

I am using CSS transform property scaleX for my animation. See CodePen. Unfortunately the red box on the left has no effects on hover and its not transforming like the other 3 ones. From my understanding, as the red box has no space on it's left that is why it cannot transform on hover. Is there any good solution for my problem?
HTML
<div class="container-fluid mt-3">
<div class="row">
<div class="col-sm-3">
<div class="img-holder">
<div class="image image1"></div>
</div>
</div>
<div class="col-sm-3">
<div class="img-holder">
<div class="image image2"></div>
</div>
</div>
<div class="col-sm-3">
<div class="img-holder">
<div class="image image3"></div>
</div>
</div>
<div class="col-sm-3">
<div class="img-holder">
<div class="image image4"></div>
</div>
</div>
</div>
</div>
You can also reset z-index on :hover and eventually transform-origin for the first and last element:
.image1 {
background-color: red;
}
.image2 {
background-color: green;
}
.image3 {
background-color: blue;
}
.image4 {
background-color: pink;
}
.image {
height: 15vw;
}
.img-holder {
position: relative;
width: 100%;
}
.img-holder .image {
width: 100%;
position: relative;
z-index: 5;
transition: all 0.5s ease;
}
.img-holder .image:hover {
transform: scaleX(2);
z-index: 10;
}
.col-sm-3:first-of-type :hover .image {
transform-origin: top left;
}
.col-sm-3:last-of-type :hover .image {
transform-origin: top right;
}
.col-sm-3 {
padding: 0;
}
<div class="container-fluid mt-3">
<div class="row">
<div class="col-sm-3">
<div class="img-holder">
<div class="image image1"></div>
</div>
</div>
<div class="col-sm-3">
<div class="img-holder">
<div class="image image2"></div>
</div>
</div>
<div class="col-sm-3">
<div class="img-holder">
<div class="image image3"></div>
</div>
</div>
<div class="col-sm-3">
<div class="img-holder">
<div class="image image4"></div>
</div>
</div>
</div>
</div>
https://codepen.io/gc-nomade/pen/dzvypQ