Home > Article > Web Front-end > How to achieve animation effect of changing width in css3
Method: 1. Use the "element {animation: name time}" statement to bind animation to the element; 2. Use the "@keyframes name {100%{width: width value;}}" statement to set the element The animation action of changing the width realizes the animation effect of the element changing the width.
The operating environment of this tutorial: Windows 10 system, CSS3&&HTML5 version, Dell G3 computer.
How to achieve the animation effect of changing the width of css3
In css, you can use the animation attribute and @keyframes rule to change the width of the element Animation effects, through @keyframes rules, can create animations.
The principle of creating animation is to gradually change one set of CSS styles into another set of styles. You can change this set of CSS styles multiple times during the animation.
Specify the time when the change occurs as a percentage, or through the keywords "from" and "to", which are equivalent to 0% and 100%. 0% is the start time of the animation, 100% is the end time of the animation. For best browser support, you should always define 0% and 100% selectors.
Use the width attribute to set the animation action. This property is used to set the width of the element.
The syntax format of the animation attribute is as follows:
animation: name duration timing-function delay iteration-count direction;
The example is as follows:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> div{ width:100px; height:100px; margin:0 auto; background-color:pink; animation:fadenum 5s; } @keyframes fadenum{ 100%{width:300px;} } </style> </head> <body> <div></div> </body> </html>
Output result:
(Learn Video sharing: css video tutorial)
The above is the detailed content of How to achieve animation effect of changing width in css3. For more information, please follow other related articles on the PHP Chinese website!