<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>立方体</title>
</head>
<style> * { padding: 0; margin: 0; } #wrap { width: 400px; height: 400px; border: 1px solid #000; position: absolute; left: 50%; top: 50%; margin-left: -200px; margin-top: -200px; perspective: 200px; /* transform-style: preserve-3d; */ } #wrap .box { width: 100px; height: 100px; position: absolute; left: 50%; top: 50%; margin-left: -50px; margin-top: -50px; transition: all 2s; transform-origin: center center -50px; transform-style: preserve-3d; } #wrap .box div { position: absolute; width: 100px; height: 100px; text-align: center; background: rgba(0, 0, 0, .3); font: 50px/100px "微软雅黑"; } #wrap .box div:nth-child(1) { z-index: 1; } #wrap .box div:nth-child(2) { transform: translateZ(-100px) rotateX(180deg); } #wrap .box div:nth-child(3) { transform-origin: right; transform: rotateY(-90deg); left: -100px; } #wrap .box div:nth-child(4) { transform-origin: left; transform: rotateY(90deg); right: -100px; } #wrap .box div:nth-child(5) { transform-origin: bottom; transform: rotateX(90deg); top: -100px; } #wrap .box div:nth-child(6) { transform-origin: top; transform: rotateX(-90deg); bottom: -100px; } #wrap:hover .box { transform: rotateX(360deg); } </style>
<body>
<div id="wrap">
<div class="box">
<div>前</div>
<div>后</div>
<div>左</div>
<div>右</div>
<div>上</div>
<div>下</div>
</div>
</div>
</body>
</html>