1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> *{ margin:0; padding:0; } body{ background-color: } .cube{ margin:100px auto; width:200px; height:200px; perspective: 250px; -webkit-perspective: 250px; transform-style:preserve-3d;/*指定元素的子元素在3D空间内定位*/ -webkit-transform-style:preserve-3d; perspective-origin: -100% -50%;/*指定用户从哪个方向看过来*/ -webkit-perspective-origin: -100% -50%; } .cube div{ display:block; position:absolute; width:100px; height:100px; line-height:100px; font-size:30px; text-align:center; } .front{ border:none; background:rgba(0, 0, 0, 0.3); transform:translateZ(50px); -webkit-transform:translateZ(50px); } .back{ background:rgba(0, 225, 0, 1); transform:translateZ(-50px); -webkit-transform:translateZ(-50px); } .right{ background:rgba(196, 0, 0, 0.7); transform:rotateY(90deg) translateZ(50px); -webkit-transform:rotateY(90deg) translateZ(50px); } .left{ background:rgba(0, 0, 196, 0.7); transform:rotateY(-90deg) translateZ(50px); -webkit-transform:rotateY(-90deg) translateZ(50px); } .top{ background:rgba(196, 196, 0, 0.7); transform:rotateX(90deg) translateZ(50px); -webkit-transform:rotateX(90deg) translateZ(50px); } .bottom{ background:rgba(196, 0, 196, 0.7); transform:rotateX(90deg) translateZ(50px); -webkit-transform:rotateX(-90deg) translateZ(50px); } </style> </head> <body> <div class="cube"> <div class="front">1</div> <div class="back">2</div> <div class="right">3</div> <div class="left">4</div> <div class="top">5</div> <div class="bottom">6</div> </div> </body> </html>
|