css布局实现一个三维游戏场景效果代码
代码语言:html
所属分类:三维
代码描述:css布局实现一个三维游戏场景效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<link href="https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap" rel="stylesheet">
<style>
/***********************/
/***********************/
/***********************/
*, *::after, *::before {
margin: 0;
padding: 0;
box-sizing: border-box;
transform-style: preserve-3d;
user-select: none;
-webkit-tap-highlight-color: transparent;
appearance: none;
font-family: "Press Start 2P", cursive;
}
/***********************/
/***********************/
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
width: 100%;
overflow: hidden;
cursor: pointer;
background-color: #5b7efd;
color: white;
}
.face {
position: absolute;
}
.flex {
display: flex;
justify-content: center;
align-items: center;
}
/***********************/
/***********************/
.main {
position: absolute;
width: 30vw;
height: 30vw;
transform: perspective(20000px) rotateX(60deg) rotateZ(30deg) translateZ(-10vw);
transition: transform 50ms linear;
}
.shadow {
position: absolute;
right: -2%;
bottom: -2%;
width: 106%;
height: 106%;
transform: translateZ(-5.1vw);
background-color: #335efd;
box-shadow: 0.5vw 0.5vw 0.5vw #335efd, -0.5vw 0.5vw 0.5vw #335efd, 0.5vw -0.5vw 0.5vw #335efd, -0.5vw -0.5vw 0.5vw #335efd;
}
/*---------------------*/
.a {
position: absolute;
width: 30vw;
height: 30vw;
}
.a__front {
width: 30vw;
height: 4vw;
transform-origin: bottom left;
transform: rotateX(-90deg) translateZ(26vw);
}
.a__back {
width: 30vw;
height: 4vw;
transform-origin: top left;
transform: rotateX(-90deg) rotateY(180deg) translateX(-30vw) translateY(-4vw);
}
.a__right {
width: 30vw;
height: 4vw;
transform-origin: top left;
transform: rotateY(90deg) rotateZ(-90deg) translateZ(30vw) translateX(-30vw) translateY(-4vw);
}
.a__left {
width: 30vw;
height: 4vw;
transform-origin: top left;
transform: rotateY(-90deg) rotateZ(90deg) translateY(-4vw);
}
.a__top {
width: 30vw;
height: 30vw;
transform-origin: top left;
transform: translateZ(4vw);
}
.a__bottom {
width: 30vw;
height: 30vw;
transform-origin: top left;
transform: rotateY(180deg) translateX(-30vw);
}
.a__front {
background-color: #b8511f;
border-bottom: 0.5vw solid #017101;
}
.a__back {
background-color: #9e451b;
border-bottom: 0.5vw solid #005800;
}
.a__right {
background-color: #dd6d38;
border-bottom: 0.5vw solid #01bd01;
}
.a__left {
background-color: #9e451b;
border-bottom: 0.5vw solid #005800;
}
.a__top {
background-color: #01bd01;
background-image: repeating-linear-gradient(45deg, #019401 25%, transparent 25%, transparent 75%, #019401 75%, #019401), repeating-linear-gradient(45deg, #019401 25%, transparent 25%, transparent 75%, #019401 75%, #019401);
background-position: 0 0, 5vw 5vw;
background-size: 10vw 10vw;
}
.a__bottom {
background-color: #803816;
}
.b {
position: absolute;
top: 0;
left: 0;
width: 20vw;
height: 15vw;
transform: translateZ(4vw);
}
.b__front {
width: 20vw;
height: 4vw;
transform-origin: bottom left;
transform: rotateX(-90deg) translateZ(11vw);
}
.b__back {
width: 20vw;
height: 4vw;
transform-origin: top left;
transform: rotateX(-90deg) rotateY(180deg) translateX(-20vw) translateY(-4vw);
}
.b__right {
width: 15vw;
height: 4vw;
transform-origin: top left;
transform: rotateY(90deg) rotateZ(-90deg) translateZ(20vw) translateX(-15vw) translateY(-4vw);
}
.b__left {
width: 15vw;
height: 4vw;
transform-origin: top left;
transform: rotateY(-90deg) rotateZ(90deg) translateY(-4vw);
}
.b__top {
width: 20vw;
height: 15vw;
transform-origin: top left;
transform: translateZ(4vw);
}
.b__bottom {
width: 20vw;
height: 15vw;
transform-origin: top left;
transform: rotateY(180deg) translateX(-20vw);
}
.b__front {
background-image: linear-gradient(39deg, #b8511f 12.6vw, transparent 12.6vw);
}
.b__back {
background-image: linear-gradient(-39deg, #9e451b 12.6vw, transparent 12.6vw);
}
.b__left {
background-color: #9e451b;
}
.b__top {
background-image: linear-gradient(to right, #ca5822 15vw, transparent 15vw);
}
.b__top::after {
content: "";
position: absolute;
height: 100%;
width: 15vw;
background-color: #01bd01;
background-image: repeating-linear-gradient(45deg, #019401 25%, transparent 25%, transparent 75%, #019401 75%, #019401), repeating-linear-gradient(45deg, #019401 25%, transparent 25%, transparent 75%, #019401 75%, #019401);
background-position: 0 0, 5vw 5vw;
background-size: 10vw 10vw;
}
.b__top::before {
content: "";
position: absolute;
right: -1.5vw;
width: 6.5vw;
height: 100%;
transform-origin: left;
transform: rotateY(39deg);
background-color: #019401;
background-image: repeating-linear-gradient(45deg, #01bd01 25%, transparent 25%, transparent 75%, #01bd01 75%, #01bd01), repeating-linear-gradient(45deg, #01bd01 25%, transparent 25%, transparent 75%, #01bd01 75%, #01bd01);
background-position: 0 0, 5vw 5vw;
background-size: 10vw 10vw;
}
.b__bottom {
background-color: #803816;
}
.cube {
width: 5vw;
height: 5vw;
position: absolute;
bottom: 5vw;
left: 5vw;
transform: translateZ(10vw);
}
.cube__front {
width: 5vw;
height: 5vw;
transform-origin: bottom left;
transform: rotateX(-90deg) translateZ(0vw);
}
.cube__back {
width: 5vw;
height: 5vw;
transform-origin: top left;
transform: rotateX(-90deg) rotateY(180deg) translateX(-5vw) translateY(-5vw);
}
.cube__right {
width: 5vw;
height: 5vw;
transform-origin: top left;
transform: rotateY(90deg) rotateZ(-90deg) translateZ(5vw) translateX(-5vw) translateY(-5vw);
}
.cube__left {
width: 5vw;
height: 5vw;
transform-origin: top left;
transform: rotateY(-90deg) rotateZ(90deg) translateY(-5vw);
}
.cube__top {
width: 5vw;
height: 5vw;
transform-origin: top left;
transform: translateZ(5vw);
}
.cube__bottom {
width: 5vw;
height: 5vw;
transform-origin: top left;
transform: rotateY(180deg) translateX(-5vw);
}
.cube__front {
background-color: #ab7e0f;
border: 0.3vw solid #b8511f;
color: #b8511f;
}
.cube__back {
background-color: #7c5c0b;
border: 0.3vw solid #803816;
color: #803816;
}
.cube__right {
background-color: #daa113;
border: 0.3vw solid #dd6d38;
color: #dd6d38;
}
.cube__left {
background-col.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0