CSS Transition
一句话解释
CSS transition smoothly interpolates 属性从 one 值到 another over specified duration.
用大白话说
CSS transitions let you smoothly animate changes to CSS properties. When a property changes value (e.g., on hover), the browser interpolates between the old and new values over a duration you specify, creating a smooth animation.
The transition shorthand takes: property, duration, timing function, and delay. For example, transition: background 0.3s ease animates the background color over 0.3 seconds with an ease curve. You can transition multiple properties with commas.
Transitions are triggered by property changes — usually from pseudo-classes like :hover, :focus, or class changes via JavaScript. Not all properties are transitionable (display cannot transition), but most visual properties (color, opacity, transform, width, height) can be. Transitions are simpler than @keyframes animations and are ideal for simple state changes.
示例
.btn {
background: blue;
transition: background 0.3s ease, transform 0.2s;
}
.btn:hover {
background: darkblue;
transform: scale(1.05);
}button 那个 smoothly 更改 background 颜色 and scales 上 on hover, over 0.3s and 0.2s respectively.
相关术语
相关资源
相关课程
- CSS Animations
Transitions and animations.
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。