css3 3D盒子效果

时间:2022-03-11 05:14:31
 <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
body{
margin: 0;
}
ul{
margin: 0;
padding: 0;
list-style: none;
}
.wrap{
width: 198px;
height: 198px;
padding: 198px;
border: 1px solid black;
margin: 200px auto;
perspective: 300px;
}
.wrap ul{
width: 198px;
height: 198px;
position: relative;
transition: 10s;
transform-style: preserve-3d;
transform-origin: center center -99px;
}
.wrap ul li{
width: 198px;
height: 198px;
position: absolute;
font: 50px/100px "微软雅黑";
text-align: center;
color: #fff;
background-image: url(bg.jpg);
background-repeat: no-repeat;
}
.wrap ul li:nth-of-type(1){
background-color: red;
left: 0;
top: -198px;
transform-origin: bottom;
transform: rotateX(90deg);
background-position: -393px -393px;
}
.wrap ul li:nth-of-type(2){
background-color: yellow;
left: -198px;
top: 0;
transform-origin: right;
transform: rotateY(-90deg);
background-position: 0 -198px;
}
.wrap ul li:nth-of-type(3){
background-color: blue;
left: 0;
top: 0;
transform: translateZ(0px);
background-position: -197px -196px;
}
.wrap ul li:nth-of-type(4){
background-color: green;
left: 198px;
top: 0;
transform-origin: left;
transform: rotateY(90deg);
background-position: -393px -196px;
}
.wrap ul li:nth-of-type(5){
background-color: pink;
left: 0;
top: 198px;
transform-origin: top;
transform: rotateX(-90deg);
background-position: -589px -196px;
}
.wrap ul li:nth-of-type(6){
background-color: purple;
left: 0;
top: 0;
transform: translateZ(-198px);
background-position: -393px 0;
}
.wrap:hover ul{
transform:rotateX(720deg) rotateY(720deg) rotateZ(720deg);
}
</style>
</head>
<body>
<div class="wrap">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
</ul>
</div>
</body>
</html>

效果图:

css3 3D盒子效果