Creative 3D Ambient Light Effects | CSS Cube Animation Effects

Creative 3D Ambient Light Effects | CSS Cube Animation Effects


Welcome to my website U-GINE MEDIA. In this website I teach tutorials and share source code on some programming (HTML, CSS & JavaScript) tutorials. 

Before we get started, do well to subscribe to my channel to never miss out on any update that I post every single day.

In this tutorial topic "Creative 3D Ambient Light Effects | CSS Cube Animation Effects", we will learn how to create it following these simple easy steps.

Share this to your programmer friends. I hope y'all learnt something today, make sure to let me in the comments. 

If interested in watching the video before running the code below, you can click the play button to get started.


Code Begins

  1. First, create a folder with any name you like. Then, make the necessary files inside it.
  2. Create a file called index.html to serve as the main file.
  3. Create a file called style.css for the CSS code.
  4. Finally, Create a file called script.js for the JavaScript code.

To start, add the following HTML codes to your index.html file. These codes include essential HTML markup with different semantic tags, such as div, form, input, button, image, etc., to build the website layout. 


<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="stylesheet" href="index.css">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Creative 3d Cube Effects</title>
</head>
<body>

<div class="cube">
    <div class="top"></div>
    <div class="bottom"></div>
    <div>
        <span style="--i:0"></span>
        <span style="--i:1"></span>
        <span style="--i:2"></span>
        <span style="--i:3"></span>
    </div>
</div>

<div class="cube cube2">
    <div class="top"></div>
    <div class="bottom"></div>
    <div>
        <span style="--i:0"></span>
        <span style="--i:1"></span>
        <span style="--i:2"></span>
        <span style="--i:3"></span>
    </div>
</div>

    
</body>
</html>

Finally, add the following CSS codes to your style.css file to make your AI image generator website beautiful and user-friendly. You can customize the different CSS properties, such as color, background, font, etc., to give a personalized touch to your website. 



* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10em;
    background: #050505;
}

.cube {
    position: relative;
    width: 100px;
    height: 100px;
    cursor: pointer;
    transform-style: preserve-3d;
    transform: rotateX(-30deg);
    animation: animate 4s linear infinite;
}

@keyframes animate {
    0% {
        transform: rotateX(-30deg) rotateY(0deg);
    }100% {
        transform: rotateX(-30deg) rotateY(360deg);
    }
}

.cube div {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
}

.cube div span {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transition: 1s;
    background: linear-gradient(#151515, #0f0);
    transform: rotateY(calc(90deg * var(--i))) translateZ(20px);
}

.cube:hover div span {
    transform: rotateY(calc(90deg * var(--i))) translateZ(50px);
}

.cube:hover .bottom {
    opacity: 1;
}

.cube:hover .top {
    opacity: 1;
}


.top {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #050505;
    transform: rotateX(90deg) translateZ(50px);
    opacity: 0;
    transition: 1s;
}

.bottom {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #0f0;
    opacity: 0;
    transition: 1s;
    transform: rotateX(90deg) translateZ(-100px);
    filter: blur(5px);
    box-shadow: 0 0 120px #0f0,
                0 0 200px #0f0,
                0 0 300px #0f0,
                0 0 400px #0f0;
}

.cube2 {
    animation: animate2 4s linear infinite;
}

.cube2 div span {
    background: linear-gradient(#151515, red);
}

.cube2 .bottom {
    background: red;
    box-shadow: 0 0 120px red,
                0 0 200px red,
                0 0 300px red,
                0 0 400px red;
}

@keyframes animate2 {
    0% {
        transform: rotateX(-30deg) rotateY(0deg);
    }100% {
        transform: rotateX(-30deg) rotateY(-360deg);
    }
}


Conclusion and Final word

Now, we have reached the end of our code, for any information, you can comment any problem or code-not-working issues to resolve it, am always with you. You can also visit my YouTube Channel for more updates on HTML, CSS & JavaScript Designs. I believe you can create a 3D ambient light effects using CSS.

Happy Coding Journey 🚀

Post a Comment

0 Comments

Close Menu