While wondering how to make CSS animation, many users go looking for tutorials and tutorials. Although you will find similar instructions here, among other things, we will give you the main useful tip in creating animation with CSS.
The secret of perfect designs
The biggest piece of advice I can give to those who want to know the full extent of what CSS smooth animation is is this. When experimenting daily with ready-made pieces of code, try to conduct your own experiments as well. During your free time from working on your own sites, try to see what happens when you add this or that piece of code, to study this or that property to the fullest. Try to implement all sorts of interesting ideas using completely different language tools, and CSS animation will open up for you in a new way. This simple tip is to experiment for yourself.
CSS spawn animation
And now let's move on to interesting examples. As a rule, the standard use of animation is to change some elements of the site smoothly over time. But it's too banal, don't you think? Therefore, here we will share with you an extraordinaryway to use the timing of the animation.
The fact is that real changes on the site in a piece of animation or in its full form can be almost instantaneous. To do this, we set any two keyframes, but at the same time we use a very small interval. For example, it could be 0.001%. In this case, the CSS animation can happen instantly. This is great for imitating some kind of neon sign. This sign will flash, and if the CSS animation also uses transparency and the text-shadow property, then the sign will turn out almost like a real one.
Let's give an example code.
Improving the functionality of the buttons
If we consider how unusual a CSS button animation can be, we can say that there are a lot of options for decorating buttons on websites. Let's consider one of the examples. The effect of a pressed convex button. Sample code is below.
With this simple piece of code, the CSS block animation will look pretty good. It looks very interesting and is often used on completely different sites.
CSS animation when hovering over a site fragment
The more dynamic and modern the site, the longer the user stays on it. In addition, interactivity also plays an important role. Of course, this is true, but what can help make the site as interactive as possible?
Working with the design of elements and fragments of the site on mouse hover looks very good here. We discussed the animation of the buttons on hover above, but in addition, you can "revive" all kinds of parts of the site, making them as stylish as possible. As with everything else, the main principle here is not to overdo it.
So there's an awesome transition property that can take up to four associated properties.
During a certain time, the CSS animation will change when hovering over this piece of code. The time is determined by the duration property. That is, when you hover over an element, some property that we set in the selector will start to change in a peculiar way. For our case, this is.element (dot in front). Below is a code example where a container div that has the.hover pseudo-class changes its background from red to green when transitioning.
When the user mouses over, the CSS animation does not change immediately, but with a delay of a fraction of a second, which creates an interesting effect.
In addition, if in the previous example you set a specific rule according to which the background of the div element should change from red to green within 0.4 seconds, then you should note that using the value all, you can access the entire property at once.
An example code will be presented as follows.
As shown,padding and background properties, a transition effect will occur, which is determined by the transition property. You should note that you can specify a whole specific set of values separated by commas.
Several nuances of using this type of animation on buttons
In principle, by and large it is not so important in what order these values will be indicated and listed. Except one case. We can deal with the delay property. In this case, we will need to specify the time duration as well. In other words, we will need to tell in the code how long the delay we need will last.
Be aware that some properties cannot have a transition effect. That is, they cannot be transient. This is because they may no longer be animated.
Great CSS text animation can also be set using code. It can be some kind of article, and a large headline, the title of the site. As mentioned above, the main thing here is not to overdo it and not turn your site into a dump that will look cheap.
Well, let's try to find out what CSS text animation is and how to create it and text shadows. Perhaps you have seen horror films in which the names of the pictures themselves seemed to fade against some gloomy dark background. Let's try to recreate something similar using a general example.
Animate Horror Movie Style Text
Actually, the whole idea is to make the text in which the letterswould be a little blurry and would rotate. There must be space between letters. We will use letter shadows as well as spacing. In order to implement the idea, we need the Lettering.js script by Dave Rupert. It is needed to wrap words plus letters in multiple span tags. First you need to wrap the phrases in an h2 tag. Here is a code example.
Then wrap all words in h2 tags in a span tag.
It will happen like this.
This will look a bit cumbersome, but don't let that bother you.
This is a pretty crazy structure.
As a result, we wrapped each of the letters we have in a span tag. There really were a lot of them. But in the code above, the example is rather simplified. You can write the entire structure yourself, and it will be somewhat larger. It also depends on what text you will use.
Let's finish our work with some little styling. All our headings in the above example will be located in the entire width of the screen. And they will take up almost all the free space.
Since we're going to center all of our letters on the screen, for our container we also need toflexbox will also be required.
Let's give an example of his code.
Now we have made it so that all the letters that are wrapped in the span class, which belongs to the parent.os-phrases class, will be positioned and anchored exactly in the center.
Don't forget to add some free space, i.e. the letter spacing itself.
In this case, the first wrapper will, as it were, have a certain additional property. This is the perspective property. It will allow us to make this area seem to stand out, to come to the fore.
Our letters themselves will be transparent, and we will start the animation interval for them somewhere in 5.2 seconds. Below is a sample code.
It is also important to determine how and with what delay our sentences and phrases will appear. Which part of the text will appear faster than the previous one, and by how much. The code will look like this.
Let's give a small but very curious effect. Set the opacity to 0, 2. The letter spacing will be quite large. The letters will also be slightly rotated along the Y axis. You, as well as users of your site, will see only a small part of these letters. Also don't forget to give effect to the text-shadow property. In the middle of the animation, we will do an unusual thing. We will sharpen the letters themselves, and also reduce the distance thatlocated between them, then increase the opacity, and then rotate the signs to 0 on the Y axis.
At the end we'll add the disappearing letters again and scale them up a bit. This will again give a slight blur effect.
And finally the last sentence of the CSS animation.
And yes, finally, let's add the final touch. Let's focus on some specific words. They will be bold. This will give the necessary accent.
Don't forget about sources of inspiration as well
When you're trying to experiment with CSS properties and animations yourself, try to find inspiration in everything in your daily life. It can be anything from an interesting web page to some great video effect.
Besides, if you do not peep how this or that effect is made, but try to recreate it on your own, you can achieve great results. Or, at least, always learn something more about the capabilities of the programming language that you actually use. Even an idea not fully realized by you may well turn out to be very effective.