如何使用 CSS 在悬停时缩放元素?
cssweb developmentfront end technology更新于 2025/12/3 14:04:17
要使用 CSS 在悬停时缩放元素,代码如下: −
示例
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
* {
box-sizing: border-box;
}
.zoomDiv {
padding: 50px;
background-color: yellow;
transition: transform 0.2s;
width: 200px;
height: 200px;
margin: 70px;
border-radius: 50%;
border: 4px solid rgb(78, 37, 155);
}
.zoomDiv:hover {
transform: scale(1.5);
}
</style>
</head>
<body>
<h1>Zoom on Hover Example</h1>
<h2>Hover over the below element to see it zoom.</h2>
<div class="zoomDiv"></div>
</body>
</html>
输出
上述代码将产生以下输出 −

将鼠标悬停在黄色圆圈上 −

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

