10-24-simple-3d-transform.html 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Simple 3D transform</title>
  6. <style>
  7. /**
  8. * 1. Don't forget to set the perspective with a pixel unit!
  9. * Most browsers allow you to use unitless lengths, but
  10. * some don't, so always set in pixels.
  11. * 2. We're just using height + flexbox + margin: auto to center the
  12. * element in the container here.
  13. * 3. Some prefixes are needed for legacy support.
  14. * 4. Setting the body to flex, just to line up the wrappers.
  15. */
  16. .wrapper-2 {
  17. -webkit-perspective: 140px; /* 1 */
  18. -moz-perspective: 140px; /* 1 */
  19. -o-perspective: 140px; /* 1 */
  20. perspective: 140px; /* 1 */
  21. }
  22. .wrapper-3 {
  23. -webkit-perspective: 800px; /* 1 */
  24. -moz-perspective: 800px; /* 1 */
  25. -o-perspective: 800px; /* 1 */
  26. perspective: 800px; /* 1 */
  27. }
  28. [class^="wrapper"] {
  29. width: 150px;
  30. display: -ms-flexbox; /* 2 */
  31. display: -webkit-box; /* 2 */
  32. display: -webkit-flex; /* 2 */
  33. display: -moz-box; /* 2 */
  34. display: flex; /* 2 */
  35. }
  36. .box {
  37. margin: auto; /* 2 */
  38. border: 2px solid;
  39. width: 100px;
  40. height: 100px;
  41. -webkit-transform: rotateY(60deg); /* 3 */
  42. -moz-transform: rotateY(60deg); /* 3 */
  43. -o-transform: rotateY(60deg); /* 3 */
  44. transform: rotateY(60deg); /* 3 */
  45. }
  46. html, body {
  47. height: 100%;
  48. }
  49. body {
  50. display: flex; /* 4 */
  51. }
  52. </style>
  53. </head>
  54. <body>
  55. <div class="wrapper-1">
  56. <div class="box"></div>
  57. </div>
  58. <div class="wrapper-2">
  59. <div class="box"></div>
  60. </div>
  61. <div class="wrapper-3">
  62. <div class="box"></div>
  63. </div>
  64. </body>
  65. </html>