<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .box { padding: 0 5px; width: 200px; height: 40px; line-height: 40px; background-color: pink; border-radius: 15px; /* 谁做过渡给谁加,transition: 要过渡的属性 花费时间 运动曲线(可省略) 何时开始(可省略) */ transition: all 1.5s; /* 强制一行显示,超出则用省略号代替 */ white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; } .box:hover { width: 500px; /* 阴影 */ box-shadow: 10px 10px 10px -4px rgba(0, 0, 0, 0.5); } </style> </head> <body> <div class="box"> 测试动态过渡效果是否有用,看看效果怎么样吧 </div> </body> </html>