{"id":1834,"date":"2025-02-21T22:57:33","date_gmt":"2025-02-21T14:57:33","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=1834"},"modified":"2025-02-21T22:57:33","modified_gmt":"2025-02-21T14:57:33","slug":"css3-3d-%e8%bd%ac%e6%8d%a2","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2025\/02\/21\/css3-3d-%e8%bd%ac%e6%8d%a2\/","title":{"rendered":"CSS3 3D \u8f6c\u6362"},"content":{"rendered":"\n<p>CSS3 3D \u8f6c\u6362\u4e3a\u7f51\u9875\u5143\u7d20\u63d0\u4f9b\u4e86\u66f4\u590d\u6742\u7684\u4e09\u7ef4\u6548\u679c\uff0c\u80fd\u591f\u8ba9\u4f60\u5b9e\u73b0\u66f4\u52a0\u751f\u52a8\u7684\u89c6\u89c9\u6548\u679c\u3002\u901a\u8fc7 3D \u8f6c\u6362\uff0c\u4f60\u53ef\u4ee5\u5728\u4e09\u7ef4\u7a7a\u95f4\u4e2d\u5bf9\u5143\u7d20\u8fdb\u884c\u65cb\u8f6c\u3001\u5e73\u79fb\u3001\u7f29\u653e\u7b49\u64cd\u4f5c\u3002\u4e0e 2D \u8f6c\u6362\u76f8\u6bd4\uff0c3D \u8f6c\u6362\u6dfb\u52a0\u4e86\u4e00\u4e2a\u6df1\u5ea6\u7ef4\u5ea6\uff0c\u4f7f\u5f97\u9875\u9762\u6548\u679c\u66f4\u52a0\u7acb\u4f53\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong>\u57fa\u672c\u7684 3D \u8f6c\u6362\u5c5e\u6027<\/strong><\/h3>\n\n\n\n<p>\u4e0e 2D \u8f6c\u6362\u4e00\u6837\uff0c3D \u8f6c\u6362\u4e5f\u4f7f\u7528 <code>transform<\/code> \u5c5e\u6027\uff0c\u4e0d\u8fc7\u5b83\u6d89\u53ca\u5230\u7684\u64cd\u4f5c\u4f1a\u6709\u6df1\u5ea6\u7ef4\u5ea6\uff08z\u8f74\uff09\u3002\u5e38\u7528\u7684 3D \u8f6c\u6362\u5305\u62ec\uff1a\u65cb\u8f6c\uff08rotate\uff09\u3001\u5e73\u79fb\uff08translate\uff09\u3001\u7f29\u653e\uff08scale\uff09\u7b49\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1.1 <strong>rotateX\u3001rotateY\u3001rotateZ<\/strong><\/h4>\n\n\n\n<p>\u8fd9\u4e9b\u5c5e\u6027\u7528\u4e8e\u6cbf X\u3001Y \u6216 Z \u8f74\u65cb\u8f6c\u5143\u7d20\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>div {\n  transform: rotateX(45deg); \/* \u6cbf X \u8f74\u65cb\u8f6c 45 \u5ea6 *\/\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>div {\n  transform: rotateY(30deg); \/* \u6cbf Y \u8f74\u65cb\u8f6c 30 \u5ea6 *\/\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>div {\n  transform: rotateZ(60deg); \/* \u6cbf Z \u8f74\u65cb\u8f6c 60 \u5ea6 *\/\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">1.2 <strong>translateZ<\/strong><\/h4>\n\n\n\n<p><code>translateZ<\/code> \u7528\u4e8e\u6cbf Z \u8f74\u79fb\u52a8\u5143\u7d20\uff0c\u53ef\u4ee5\u6a21\u62df\u5143\u7d20\u8fdc\u8fd1\u7684\u6548\u679c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>div {\n  transform: translateZ(100px); \/* \u5411\u5c4f\u5e55\u5916\u79fb\u52a8 100 \u50cf\u7d20 *\/\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">1.3 <strong>scale3d<\/strong><\/h4>\n\n\n\n<p><code>scale3d<\/code> \u7528\u4e8e\u5728 3D \u7a7a\u95f4\u4e2d\u7f29\u653e\u5143\u7d20\uff0c\u5141\u8bb8\u4f60\u5728\u4e09\u4e2a\u8f74\u4e0a\u8fdb\u884c\u4e0d\u540c\u7a0b\u5ea6\u7684\u7f29\u653e\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>div {\n  transform: scale3d(1.5, 1.5, 1.5); \/* \u540c\u65f6\u6cbf X, Y, Z \u8f74\u7f29\u653e 1.5 \u500d *\/\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>\u8bbe\u7f6e 3D \u4e0a\u4e0b\u6587<\/strong><\/h3>\n\n\n\n<p>\u5728\u8fdb\u884c 3D \u8f6c\u6362\u65f6\uff0c<code>perspective<\/code> \u5c5e\u6027\u7528\u4e8e\u8bbe\u7f6e\u89c6\u56fe\u7684\u6df1\u5ea6\uff0c\u4f7f 3D \u8f6c\u6362\u6548\u679c\u66f4\u52a0\u660e\u663e\u3002\u901a\u8fc7 <code>perspective<\/code>\uff0c\u4f60\u53ef\u4ee5\u63a7\u5236\u89c2\u5bdf\u8005\u4e0e\u5143\u7d20\u4e4b\u95f4\u7684\u8ddd\u79bb\uff0c\u4ece\u800c\u5f71\u54cd\u6df1\u5ea6\u611f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.container {\n  perspective: 500px; \/* \u8bbe\u7f6e 3D \u89c6\u8ddd *\/\n}<\/code><\/pre>\n\n\n\n<p><code>perspective<\/code> \u503c\u8d8a\u5c0f\uff0c\u5143\u7d20\u770b\u8d77\u6765\u8d8a\u63a5\u8fd1\u89c2\u4f17\uff0c\u6df1\u5ea6\u611f\u8d8a\u5f3a\uff1b\u503c\u8d8a\u5927\uff0c\u5143\u7d20\u770b\u8d77\u6765\u8d8a\u8fdc\uff0c\u6df1\u5ea6\u611f\u8d8a\u5f31\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>transform-style<\/strong><\/h3>\n\n\n\n<p><code>transform-style<\/code> \u5b9a\u4e49\u4e86\u5b50\u5143\u7d20\u5982\u4f55\u5728 3D \u7a7a\u95f4\u4e2d\u5448\u73b0\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6240\u6709\u5143\u7d20\u90fd\u662f\u5e73\u9762\u7684\uff1b\u8981\u4f7f\u7528 3D \u6548\u679c\uff0c\u5fc5\u987b\u5c06\u5143\u7d20\u8bbe\u7f6e\u4e3a <code>preserve-3d<\/code>\uff0c\u4ee5\u4fdd\u6301\u5176 3D \u7a7a\u95f4\u4e2d\u7684\u7acb\u4f53\u6548\u679c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.container {\n  transform-style: preserve-3d; \/* \u4fdd\u6301\u5b50\u5143\u7d20\u7684 3D \u7a7a\u95f4 *\/\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>\u591a\u91cd 3D \u8f6c\u6362<\/strong><\/h3>\n\n\n\n<p>\u4f60\u53ef\u4ee5\u5c06\u591a\u4e2a 3D \u8f6c\u6362\u7ec4\u5408\u5728\u4e00\u8d77\uff0c\u4ee5\u521b\u5efa\u590d\u6742\u7684 3D \u6548\u679c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>div {\n  transform: rotateX(45deg) rotateY(30deg) translateZ(200px);\n}<\/code><\/pre>\n\n\n\n<p>\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5143\u7d20\u9996\u5148\u6cbf X \u8f74\u65cb\u8f6c 45 \u5ea6\uff0c\u7136\u540e\u6cbf Y \u8f74\u65cb\u8f6c 30 \u5ea6\uff0c\u6700\u540e\u6cbf Z \u8f74\u5e73\u79fb 200px\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5. <strong>\u4f7f\u7528 3D \u8f6c\u6362\u548c\u8fc7\u6e21<\/strong><\/h3>\n\n\n\n<p>\u4f60\u53ef\u4ee5\u5c06 <code>transition<\/code> \u6216 <code>animation<\/code> \u4e0e 3D \u8f6c\u6362\u7ed3\u5408\u4f7f\u7528\uff0c\u4f7f\u5f97\u5143\u7d20\u7684 3D \u6548\u679c\u66f4\u5e73\u6ed1\u6216\u5177\u6709\u52a8\u753b\u611f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>div {\n  transition: transform 1s;\n}\n\ndiv:hover {\n  transform: rotateY(180deg) translateZ(200px);\n}<\/code><\/pre>\n\n\n\n<p>\u5f53\u9f20\u6807\u60ac\u505c\u5728 <code>div<\/code> \u4e0a\u65f6\uff0c\u5143\u7d20\u4f1a\u5e73\u6ed1\u5730\u65cb\u8f6c 180 \u5ea6\uff0c\u5e76\u6cbf Z \u8f74\u79fb\u52a8 200 \u50cf\u7d20\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7efc\u5408\u5b9e\u4f8b\uff1a\u521b\u5efa\u4e00\u4e2a 3D \u7ffb\u8f6c\u5361\u7247<\/h3>\n\n\n\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528 3D \u8f6c\u6362\u521b\u5efa\u5361\u7247\u7ffb\u8f6c\u6548\u679c\u7684\u793a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html lang=\"en\"&gt;\n&lt;head&gt;\n  &lt;meta charset=\"UTF-8\"&gt;\n  &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"&gt;\n  &lt;title&gt;CSS3 3D \u8f6c\u6362&lt;\/title&gt;\n  &lt;style&gt;\n    .container {\n      perspective: 1000px; \/* \u8bbe\u7f6e 3D \u89c6\u8ddd *\/\n      width: 300px;\n      height: 400px;\n    }\n\n    .card {\n      width: 100%;\n      height: 100%;\n      background: #3498db;\n      position: relative;\n      transform-style: preserve-3d;\n      transition: transform 0.6s;\n    }\n\n    .card:hover {\n      transform: rotateY(180deg);\n    }\n\n    .card .front, .card .back {\n      position: absolute;\n      width: 100%;\n      height: 100%;\n      backface-visibility: hidden; \/* \u9690\u85cf\u80cc\u9762 *\/\n    }\n\n    .card .back {\n      background: #e74c3c;\n      transform: rotateY(180deg); \/* \u80cc\u9762\u65cb\u8f6c 180 \u5ea6 *\/\n    }\n\n    .card .front {\n      display: flex;\n      justify-content: center;\n      align-items: center;\n      color: white;\n      font-size: 24px;\n    }\n  &lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n  &lt;div class=\"container\"&gt;\n    &lt;div class=\"card\"&gt;\n      &lt;div class=\"front\"&gt;Front&lt;\/div&gt;\n      &lt;div class=\"back\"&gt;Back&lt;\/div&gt;\n    &lt;\/div&gt;\n  &lt;\/div&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p>\u8fd9\u4e2a\u5b9e\u4f8b\u901a\u8fc7 <code>perspective<\/code> \u521b\u5efa\u4e86\u4e00\u4e2a 3D \u7a7a\u95f4\uff0c\u4f7f\u5f97\u5f53\u7528\u6237\u5c06\u9f20\u6807\u60ac\u505c\u5728\u5361\u7247\u4e0a\u65f6\uff0c\u5b83\u4f1a\u8fdb\u884c 180 \u5ea6\u7684\u7ffb\u8f6c\uff0c\u663e\u793a\u80cc\u9762\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u603b\u7ed3<\/h3>\n\n\n\n<p>CSS3 \u7684 3D \u8f6c\u6362\u5141\u8bb8\u4f60\u901a\u8fc7\u5e73\u79fb\u3001\u65cb\u8f6c\u3001\u7f29\u653e\u7b49\u65b9\u5f0f\u5728\u4e09\u7ef4\u7a7a\u95f4\u4e2d\u64cd\u63a7\u5143\u7d20\uff0c\u80fd\u591f\u4e3a\u7f51\u9875\u589e\u6dfb\u975e\u5e38\u751f\u52a8\u7684\u6548\u679c\u3002\u901a\u8fc7\u7ed3\u5408 <code>perspective<\/code>\u3001<code>transform-style<\/code> \u7b49\u5c5e\u6027\uff0c\u4f60\u53ef\u4ee5\u4e3a\u7f51\u9875\u521b\u9020\u51fa\u4ee4\u4eba\u5370\u8c61\u6df1\u523b\u7684\u89c6\u89c9\u4f53\u9a8c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CSS3 3D \u8f6c\u6362\u4e3a\u7f51\u9875\u5143\u7d20\u63d0\u4f9b\u4e86\u66f4\u590d\u6742\u7684\u4e09\u7ef4\u6548\u679c\uff0c\u80fd\u591f\u8ba9\u4f60\u5b9e\u73b0\u66f4\u52a0\u751f\u52a8\u7684\u89c6\u89c9\u6548\u679c\u3002\u901a\u8fc7 3D \u8f6c\u6362\uff0c\u4f60\u53ef\u4ee5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55],"tags":[],"class_list":["post-1834","post","type-post","status-publish","format-standard","hentry","category-css"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/1834","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=1834"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/1834\/revisions"}],"predecessor-version":[{"id":1835,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/1834\/revisions\/1835"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=1834"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=1834"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=1834"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}