要使用CSS在margin-right属性上实现动画,您可以尝试运行以下代码
<!DOCTYPE html> <html> <head> <style> div { background-color: blue; animation: myanim 4s infinite; color: white; } @keyframes myanim { 30% { margin-right: 30px; } } </style> </head> <body> <h2>Heading One</h2> <div> This is demo text. </div> </body> </html>