Video Tutorial:
For this project of background animation, we will use plain HTML and CSS. We will create a nice Background animation where square-looking boxes will appear from the bottom of the banner area, increase in size, and disappear after going on top. We used a gradient background for the banner area, but you can use any background image here if you want.
Let's start with the HTML markup for this project. The markup is very plain and straightforward. We first take a div element with the 'box' class, which will act as the container of the cubes we will animate on the homepage. Inside that, we have taken ten empty div elements. Underneath the box div, We have taken an h2 tag with some random text in it. That's is with HTML, and now we move forward with the CSS markup.
You may also like:
In the CSS markup, we first need to discard the document's default padding and the margin. Therefore we set the padding and margin to 0 for the universal selector. Then we provided a 100% width and a height of 100vh to the box div element and gave it a nice looking bluish gradient color in the background. We have given it an absolute position value for positioning the text in the h2 tag in the middle of the document. After setting up a top and left value of 50%, we used the transform translate property to bring the text to the middle. After that, we did some basic styling for the banner text like giving it the color, text-transform,font-weight, font-family, and font-size.
For the animation, we first have to style the divs in the ''box' class. We have given a universal height and width of 60px for all the ten divs we are using. Then we have given it absolute position value. Now we scattered the div around the homepage by increasing and decreasing each div's top and left value. You can position them according to your needs by changing each div inside the box class's top and left value. We provided a rgba background color and set animation with the name 'animate.' we took an animation duration of 4s, animation direction linear, and an animation iteration count of infinite. We also provided a border radius to all the divs to make it look nice. After that, we set different animation duration for each div to animate a sequential way. In keyframe CSS markup, we put the CSS so that all divs animate from a scale from 0 to 1.6. After that, We provided translate value from 0 to -250px to the Y direction and rotated the animation from 50deg to 360deg.
To create the animation effect, you need to create two separate files of HTML and CSS. After copying the code down below, paste it to your project, run the project in your browser, and see how it works. You can also download the source code of this snippet from the download button below this blog post.
CSS:
Such a nice animation. Carry on. Mate
ReplyDeleteHallo,
ReplyDeletethis question comes from Frankfurt/Main Germany:
is it possible to use for the animation little png-produkt-pictures instaead of the cubes - and how ?
vg Reinhard
yes. but use the same dimension for images
DeletePost a Comment
Please do not enter any spam link in the comment box.