transition 是「状态 A 到状态 B」的补间动画:指定属性、时长、缓动函数和延迟,当属性因 hover / class 切换而改变时,浏览器自动生成中间帧。四个子属性简写为 transition: property duration timing-function delay。
transition 的触发依赖「状态变化」本身——它不能自己启动,必须由 hover、:checked、class 增删等引起属性改变。要无需触发的连续动画,用 @keyframes + animation。
.btn { transition: transform .2s ease, box-shadow .2s ease; } .btn:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,.15); }