DEV Community

Cover image for FAN ILLUSION USING HTML AND CSS
Prince
Prince

Posted on

FAN ILLUSION USING HTML AND CSS

HTML CODE


    <button class="hover-btn">Hover to Spin</button>

    <div class="illusion-container">
        <div class="circle"></div>
        <div class="circle"></div>
        <div class="circle"></div>
        <div class="circle"></div>
        <div class="circle"></div>
        <div class="circle"></div>
    </div>



Enter fullscreen mode Exit fullscreen mode

CSS CODE


    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #111;
            margin: 0;
            flex-direction: column;
        }

        .illusion-container {
            width: 300px;
            height: 300px;
            position: relative;
        }

        .circle {
            position: absolute;
            width: 50px;
            height: 50px;
            border-radius: 50%;
            background-color: #ff6347;
            top: 80%;
            left: 50%;
            transform-origin: 0 -150px;
            transition: transform 0.5s ease-in-out, background-color 1s;
            box-shadow: 0 0 15px rgba(255, 99, 71, 0.8);
        }

        .circle:nth-child(1) {
            background-color: #ff6347;
            transform: rotate(0deg);
        }

        .circle:nth-child(2) {
            background-color: #58f5db;
            transform: rotate(60deg);
        }

        .circle:nth-child(3) {
            background-color: #ffeb3b;
            transform: rotate(120deg);
        }

        .circle:nth-child(4) {
            background-color: #ff69b4;
            transform: rotate(180deg);
        }

        .circle:nth-child(5) {
            background-color: #8a2be2;
            transform: rotate(240deg);
        }

        .circle:nth-child(6) {
            background-color: #00fa9a;
            transform: rotate(300deg);
        }

        /* Hovering over the button triggers the spinning circles */
        .hover-btn:hover ~ .illusion-container .circle {
            animation: rotateCircles 3s linear infinite, colorChange 2s linear infinite;
            box-shadow: 0 0 25px rgba(255, 255, 255, 0.8); /* Glowing effect */
        }

        /* Keyframes for circle rotation */
        @keyframes rotateCircles {
            100% {
                transform: rotate(360deg);
            }
        }

        /* Keyframes for color changes */
        @keyframes colorChange {
            0%, 100% { background-color: #ff6347; }
            25% { background-color: #58f5db; }
            50% { background-color: #ffeb3b; }
            75% { background-color: #00fa9a; }
        }

        /* Button styling */
        .hover-btn {
            padding: 10px 30px;
            background-color: #58f5db;
            border: none;
            border-radius: 25px;
            font-size: 18px;
            color: #111;
            cursor: pointer;
            transition: background-color 0.3s ease, transform 0.3s ease;
            position: absolute;
            bottom: 30px;
        }

        /* Button hover effect */
        .hover-btn:hover {
            background-color: #ff69b4;
            color: #fff;
            transform: scale(1.1);
            box-shadow: 0 0 15px rgba(255, 99, 71, 0.8); /* Glow on hover */
        }

    </style>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)