要为元素的width和height属性添加过渡效果,您可以尝试运行以下代码
<!DOCTYPE html> <html> <head> <style> div { width: 150px; height: 150px; background: blue; transition: width 3s; } div:hover { width: 250px; height: 250px; } </style> </head> <body> <h1>Heading One</h1> <p>Hover over the below box to change its width and height.</p> <div></div> </body> </html>