Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
December 26, 2021 09:08 am GMT

How to make Floating animation in HTML CSS

Animations are one of the most attractive things when it comes to Websites. Even having some little minimalistic animations can make your website much more soothing and attractive.

In this blog, we will see how to we can make a little floating animation in HTML CSS only.

Example-
Floating image demo

This gif is from my React JS OTT webapp Link here :)

Looks cool enough for loading screens right ? You can also use it for some on page element animations.
``

Let's jump into Development part !

- HTML

Put a simple image inside of a div. This image will be the one we are going to make a float.

- CSS

Design your parent div with a flex (recommended way but totally optional).
Then make a @keyframe with an animation -

@keyframes floater {  0%{transform: translateY(-10%);transition: ease 0.5s;}  50%{transform: translateY(10%);transition: ease 0.5s;}}

Now connect your animation with you're image class. And put default translateY to -10% and transition ease 0.5s for smooth animation

.float-area{  height:100vh;  display: flex;  flex-direction:column;  align-items: center;  justify-content: center;}.floating-img{  transform: translateY(-10%);  animation: floater 1.5s infinite;  transition: ease 0.5s;  width: 80px;  height:80px;}

Source code -

And Poof ! You're image is floating like a charm !

Now go on and play with the values and make it more interesting according to your needs :)

Thanks for reading my blog! Please drop a Like and Comment if you found it useful


Original Link: https://dev.to/suyashvash/how-to-make-floating-animation-in-html-css-51da

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To