通过CSS的transition和:active伪类实现按钮点击颜色平滑过渡,首先设置background-color的0.3秒缓动动画,鼠标按下时背景色由#007bff渐变至#0056b3,再配合hover悬停效果提升交互体验。
按钮点击后颜色平滑过渡,可以通过 CS
S 的 transition 和 :active 伪类来实现。关键是设置背景色(background-color)的过渡效果,让颜色变化更自然。
.smooth-btn {
padding: 10px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.3s ease;
}
.smooth-btn:active {
background-color: #0056b3;
}
.smooth-btn:hover {
background-color: #0069d9;
}