如何使用 CSS 添加悬停过渡?
cssweb developmentfront end technology更新于 2025/12/8 1:48:17
要在 CSS 上添加悬停过渡,代码如下 −
示例
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
padding: 20px;
}
.scaleBtn {
display: inline-block;
background-color: #0c1377;
border: none;
color: white;
padding: 16px 32px;
text-align: center;
font-size: 16px;
transition: 0.3s;
margin: 20px;
}
.scaleBtn:hover {
transform: scale(1.5);
}
</style>
</head>
<body>
<h1>Transition on hover example</h1>
<button class="scaleBtn">Hover Here</button>
</body>
</html>
输出
上述代码将产生以下输出 −

将鼠标悬停在“悬停在此处”按钮上方 −

相关文章
有用资源
css 参考教程 - 该教程包含有关 css 的更多信息:https://www.cainiaomax.com/css/

