效果
css3 实现div向上移动的效果代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>css实现向上移动的效果</title>
<style>
div {
width: 100px;
height: 80px;
line-height: 80px;
/*动画的过渡效果*/
transition: all .25s ease-in;
border: 0;
margin: 10px;
background-color: pink;
float: left;
font-size: 12px;
text-align: center;
}
/*鼠标移入,向上移动8个像素*/
div:hover {
transform: translateY(-8px);
}
</style>
</head>
<body>
<div>飞鸟慕鱼博客</div>
<div>feiniaomy.com</div>
</body>
</html>
注释:
transform:该属性向元素应用 2D 或 3D 转换,对元素进行旋转、缩放、移动或倾斜的操作。
transition:属性设置元素当过渡效果。