To achieve a horizontal alignment of all card containers, you can simply enclose them in a new container and utilize flexbox:
View the working example here.
Below is the code snippet:
<div class="container">
<div class="card-container" id="first">
<div class="card">
<div class="front"><h1>hello</h1></div>
<div class="back"><h1>Goodbye</h1></div>
</div>
</div>
<div class="card-container" id="second">
<div class="card">
<div class="front"><h1>hello</h1></div>
<div class="back"><h1>Goodbye</h1></div>
</div>
</div>
<div class="card-container" id="third">
<div class="card">
<div class="front"><h1>hello</h1></div>
<div class="back"><h1>Goodbye</h1></div>
</div>
</div>
<div class="card-container" id="forth">
<div class="card">
<div class="front"><h1>hello</h1></div>
<div class="back"><h1>Goodbye</h1></div>
</div>
</div>
</div>
CSS:
body {
font-family:Arial, Helvetica, sans-serif;
font-size:36px;
}
h1 {
margin:0;
}
#first {
display: flex;
justify-content: center;
margin-left:10px;
margin-top:20px;
}
#second {
display: flex;
justify-content: center;
margin-left:220px;
margin-top:20px;
}
#third {
display: flex;
justify-content: center;
margin-left:430px;
margin-top:20px;
}
#forth {
display: flex;
justify-content: center;
margin-left:640px;
margin-top:20px;
}
.card-container {
perspective:700;
}
.card {
position:relative;
color:white;
text-align:center;
line-height:200px;
margin:20px;
width:200px;
height:200px;
transition:all 0.6s ease;
transform-style:preserve-3d;
}
.front, .back {
background-color:#5677fc;
position:absolute;
top:0;
left:0;
width:200px;
height:600px;
backface-visibility:hidden;
}
.back {
transform:rotateY(180deg);
}
.card:hover {
transform:rotateY(180deg);
}
.container {
display: flex;
flex-direction: row;
}