教程 css tutorial

页面过渡动画

页面过渡动画通过对元素状态变化的动画处理,使界面更加流畅自然。常用的属性有 opacity、transform 等,结合 transition 和 keyframes 使用。


示例代码

在线代码演示
源码
<!DOCTYPE html>
<html lang="zh-CN">

<head> <meta charset="UTF-8" /> <title>页面过渡动画示例</title> <style> body { font-family: ‘Segoe UI’, Tahoma, Geneva, Verdana, sans-serif; background-color: #f5f7fa; margin: 50px; display: flex; justify-content: center; align-items: center; height: 80vh; }

.box {
  width: 150px;
  height: 150px;
  background-color: #3498db;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.5s ease;
  display: flex;
  justify-content: center;
  align-items: center;
  color: white;
  font-weight: bold;
  font-size: 1.2rem;
  user-select: none;
}

.box:hover {
  background-color: #2980b9;
  transform: scale(1.2) rotate(10deg);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

</style> </head>

<body> <div class="box">悬停我</div> </body>

</html>