1. 六个面叠在一起
2. 六个面整体水平垂直居中
3. 旋转且位移到对应的六个面上
<!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>六边形</title>
<style>
*{
margin: 0;padding: 0;
}
div{
width:200px;height: 200px;
margin: 100px auto;
border: 10px solid red;
transform-style: preserve-3d;
transform: rotateX(20deg) rotateY(30deg);
position: relative;
background-image: url(img/1.gif);
}
div p{
width: 200px;height: 200px;
position: absolute;
/* 六个面叠在一起 */
left: 0;right: 0;bottom: 0;top: 0;margin:auto;
text-align: center;line-height: 200px;font-size: 30px;
opacity: 0.9;
}
p:nth-child(1){
background-color: rgb(248, 220, 225);
transform: translateZ(-100px);
}
p:nth-child(2){
background-color: rgb(200, 240, 243);
transform: rotateY(-90deg) translateZ(100px);
}
p:nth-child(3){
background-color: rgb(248, 215, 187);
transform: rotateX(-90deg) translateZ(100px);
}
p:nth-child(4){
background-color: rgb(176, 169, 243);
transform: rotateY(90deg) translateZ(100px);
}
p:nth-child(5){
background-color: rgb(252, 186, 235);
transform: rotateX(90deg) translateZ(100px);
}
p:nth-child(6){
background-color: rgb(143, 238, 179);
transform: translateZ(100px);
}
div:hover p:nth-child(1){
transform: translateZ(-200px);
}
div:hover p:nth-child(2){
transform: rotateY(-90deg) translateZ(200px);
}
div:hover p:nth-child(3){
transform: rotateX(-90deg) translateZ(200px);
}
div:hover p:nth-child(4){
transform: rotateX(90deg) translateZ(200px);
}
div:hover p:nth-child(5){
transform: rotateX(90deg) translateZ(200px);
}
div:hover p:nth-child(6){
transform:translateZ(200px);
}
</style>
</head>
<body>
<div>
<p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>
<p>5</p>
<p>6</p>
</div>
</body>
</html>