正方体案例
- 案例名称:正方体案例
- 案例人员:杨标
- 案例平台:HTML+CSS
- 完成时间:2019年9月1日
效果图
案例说明
本案例旨在对学生的HTML及CSS的布局做一个练习,同时对3D变幻做一个充分的了解,掌握x,y,z三轴的特点
案例代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>正方体</title>
<style>
.outBox{
width: 400px;
height: 400px;
position: relative;
margin:50px auto;
}
.box {
width: 400px;
height: 400px;
position: absolute;
left: 0px;
top: 0px;
transform: rotateX(10deg) rotateY(30deg);
/*创建3D变幻空间,实现3D效果*/
transform-style: preserve-3d;
animation: a1 10s linear infinite;
margin-top: 50px;
}
@keyframes a1 {
from{
transform: rotateX(10deg) rotateY(0deg);
}
to {
transform: rotateX(10deg) rotateY(360deg) rotate(350deg);
}
}
.box>div {
width: 400px;
height: 400px;
position: absolute;
left: 0px;
top: 0px;
opacity: 0.7; /*子绝父相定位*/
background-size: 100% 100%;
}
.before {
transform: translateZ(200px);
background-image: url("./img/2013.jpg");
}
.after {
transform: rotateY(180deg) translateZ(200px);
background-image: url("./img/2014.jpg");
}
.up {
transform: rotateX(90deg) translateZ(200px);
background-image: url("./img/2015.jpg");
}
.down {
transform: rotateX(-90deg) translateZ(200px);
background-image: url("./img/2016.jpg");
}
.left {
transform: rotateY(-90deg) translateZ(200px);
background-image: url("./img/2017.jpg");
}
.right {
transform: rotateY(90deg) translateZ(200px);
background-image: url("./img/2018上.jpg");
}
</style>
</head>
<body>
<div class="outBox">
<div class="box">
<div class="before"></div>
<div class="after"></div>
<div class="up"></div>
<div class="down"></div>
<div class="left"></div>
<div class="right"></div>
</div>
</div>
</body>
</html>