Card Sliding Animation: HTML CSS @rayen-code

Card Sliding Animation: HTML CSS









HTML Code

<!-- -------------------- HTML -------------------- -->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Slide animation</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>

    <div class="slider">

        <!-- one -->
        <div class="content" style="--delay:-3">
            <div class="image">
                <img src="https://source.unsplash.com/1400x900/?cartoon" alt="">
            </div>
            <div class="name">
                <h2>Senku Ishigami</h2>
                <p>Dr. Stone</p>
            </div>
            <a href="#">follow</a>
        </div>
        <!-- two -->
        <div class="content" style="--delay:-2">
            <div class="image">
                <img src="https://source.unsplash.com/1400x900/?manga" alt="">
            </div>
            <div class="name">
                <h2>Tanjiro Kamado</h2>
                <p>Demon Slayer</p>
            </div>
            <a href="#">follow</a>
        </div>
        <!-- three -->
        <div class="content" style="--delay:-1">
            <div class="image">
                <img src="https://source.unsplash.com/1400x900/?toon" alt="">
            </div>
            <div class="name">
                <h2>Izuku Midoriya</h2>
                <p>Hero Academia</p>
            </div>
            <a href="#">follow</a>
        </div>
        <!-- four -->
        <div class="content" style="--delay:0">
            <div class="image">
                <img src="https://source.unsplash.com/1400x900/?comic" alt="">
            </div>
            <div class="name">
                <h2>Ben Tennyson</h2>
                <p>Ben 10</p>
            </div>
            <a href="#">follow</a>
        </div>
        <!-- five -->
        <div class="content" style="--delay:1">
            <div class="image">
                <img src="https://source.unsplash.com/1400x900/?anime" alt="">
            </div>
            <div class="name">
                <h2>Aether</h2>
                <p>Genshin Impact</p>
            </div>
            <a href="#">follow</a>
        </div>

    </div>
</body>

</html>

CSS Code

/*-------------------- CSS --------------------*/
/* style */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Trebuchet MS', sans-serif;
}

body {
    display: flex;
    height: 100vh;
    justify-content: center;
    align-items: center;
    background: linear-gradient(skyblue, rgb(55, 115, 255));
}

.slider {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 500px;
    height: 300px;
}

.content {
    width: 380px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: white;
    border-radius: 100px 20px 20px 100px;
    position: absolute;
    pointer-events: none;
    animation: anime 15s linear infinite;
    opacity: 0;
    animation-delay: calc(3s * var(--delay));
}

.slider:hover .content {
    animation-play-state: paused;
}

@keyframes anime {
    0% {
        opacity: 0;
        transform: translateY(100%) scale(0.5);
    }

    5%,
    20% {
        opacity: 0.4;
        transform: translateY(100%) scale(0.7);
    }

    25%,
    40% {
        opacity: 1;
        transform: translateY(0%) scale(1);
        pointer-events: auto;
    }

    45%,
    60% {
        opacity: 0.4;
        transform: translateY(-100%) scale(0.7);
    }

    65%,
    100% {
        opacity: 0;
        transform: translateY(-100%) scale(0.5);
    }
}

.image {
    width: 90px;
    height: 90px;
    background-color: white;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
    border-radius: 50%;
    padding: 5px;
    transition: 0.1s;
}

.image:hover {
    padding: 1px;
}

.image img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.name {
    margin: 10px;
    flex-grow: 2;
}

h2 {
    font-size: 18px;
}


.content a {
    text-decoration: none;
    background-color: skyblue;
    border-radius: 8px;
    padding: 10px 15px;
    margin: 10px;
    color: white;
    text-transform: uppercase;
}

.content a:hover {
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.229);

}

0 Comments