前端学习笔记83-z轴平移
z轴平移是调制元素和人眼之间的距离,值越大,距离我们越近。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box1{
width: 200px;
height: 200px;
background-color: #bfa;
transform: translateZ(100px);
}
</style>
</head>
<body>
<div class="box1"></div>
</body>
</html>
没啥变化,为啥?
z轴平移属于立体效果(近大远小),但默认情况下网页是不支持透视的。
怎么做呢?
必须设置网页的视距。
html{
perspective: 800px;
}
这个是设置当前网页的视距为800px,即人眼距离网页的距离。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
html{
perspective: 800px;
}
body{
border: 1px red solid;
background-color: rgb(241, 241, 241);
}
.box1{
width: 200px;
height: 200px;
background-color: #bfa;
margin: 200px auto;
transition:2s;
}
body:hover .box1{
transform: translateZ(300px);
}
</style>
</head>
<body>
<div class="box1"></div>
</body>
</html>