Creating animated presentation cards with JavaScript
Whether it's to introduce the team behind your project or for any other purpose, using animated presentation cards will give a successful final touch to your page. Let’s discover how to do this in this article!
Step 1
Let's start with the HTML code.
<div class="card card0">
<div class="border">
<h2>Al Pacino</h2>
<div class="icons">
<a href="#"><i class="fab fa-codepen"></i></a>
<a href="#"><i class="fab fa-instagram"></i></a>
<a href="#"><i class="fab fa-dribbble"></i></a>
<a href="#"><i class="fab fa-twitter"></i></a>
<a href="#"><i class="fab fa-facebook"></i></a>
</div>
</div>
</div>
<div class="card card1">
<div class="border">
<h2>Ben Stiller</h2>
<div class="icons">
<a href="#"><i class="fab fa-codepen"></i></a>
<a href="#"><i class="fab fa-instagram"></i></a>
<a href="#"><i class="fab fa-dribbble"></i></a>
<a href="#"><i class="fab fa-twitter"></i></a>
<a href="#"><i class="fab fa-facebook"></i></a>
</div>
</div>
</div>
<div class="card card2">
<div class="border">
<h2>Patrick Stewart</h2>
<div class="icons">
<a href="#"><i class="fab fa-codepen"></i></a>
<a href="#"><i class="fab fa-instagram"></i></a>
<a href="#"><i class="fab fa-dribbble"></i></a>
<a href="#"><i class="fab fa-twitter"></i></a>
<a href="#"><i class="fab fa-facebook"></i></a>
</div>
</div>
</div>
Step 2
For this example, we will use Flexbox on our body
tag.
body {
display: flex;
align-items: center;
justify-content: space-around;
flex-wrap: wrap;
height: 100vh;
}
Step 3
Now, let's take care of the cards.
.card {
height: 379px;
width: 300px;
border-radius: 10px;
transition: all 0.8s;
overflow: hidden;
background: black;
box-shadow: 0 70px 63px -60px #000000;
display: flex;
justify-content: center;
align-items: center;
position: relative;
}
Step 4
So, we have our cards: let's integrate the white frame and its appearance on hover.
.border {
height: 369px;
width: 290px;
border-radius: 10px;
transition: all 1s;
position: relative;
}
.border:hover {
border: 1px solid white;
}
Step 5
We now have our cards and borders, but we only have black backgrounds... That's not very nice. Let's change that by adding photos to each card!
.card0 {
background: url('https://i.pinimg.com/736x/8f/a0/51/8fa051251f5ac2d0b756027089fbffde--terry-o-neill-al-pacino.jpg') center center no-repeat;
background-size: 300px;
}
.card0:hover {
background: url('https://i.pinimg.com/736x/8f/a0/51/8fa051251f5ac2d0b756027089fbffde--terry-o-neill-al-pacino.jpg') left center no-repeat;
background-size: 600px;
}
.card1 {
background: url('https://i.pinimg.com/originals/28/d2/e6/28d2e684e7859a0dd17fbd0cea00f8a9.jpg') center center no-repeat;
background-size: 300px;
}
.card1:hover {
background: url('https://i.pinimg.com/originals/28/d2/e6/28d2e684e7859a0dd17fbd0cea00f8a9.jpg') left center no-repeat;
background-size: 600px;
}
.card2 {
background: url('https://i.pinimg.com/originals/ee/85/08/ee850842e68cfcf6e3943c048f45c6d1.jpg') center center no-repeat;
background-size: 300px;
}
.card2:hover {
background: url('https://i.pinimg.com/originals/ee/85/08/ee850842e68cfcf6e3943c048f45c6d1.jpg') left center no-repeat;
background-size: 600px;
}
Step 6
Now, let's style our titles and icons.
.card h2 {
font-family: Arial, sans-serif;
color: white;
margin: 20px;
opacity: 0;
transition: all 1s;
}
.fab {
opacity: 0;
transition: all 1s;
}
.icons {
position: absolute;
height: 130px;
top: 226px;
width: 50px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-around;
}
a {
color: white;
}
Step 7
Now, let's make the icons and card titles appear on hover.
.card:hover h2 {
opacity: 1;
}
.card:hover .fab {
opacity: 1;
}
Bravo! We're done!
Share your result on the official Believemy discussion channel!