{"id":1573,"date":"2022-06-22T14:51:24","date_gmt":"2022-06-22T06:51:24","guid":{"rendered":"https:\/\/fromideatocreation.com\/?p=1174"},"modified":"2023-07-02T16:37:57","modified_gmt":"2023-07-02T08:37:57","slug":"%e3%80%90next-js-%e7%b3%bb%e5%88%97%e3%80%91%e8%b3%87%e7%94%a2%e3%80%81%e5%be%8c%e8%a8%ad%e8%b3%87%e6%96%99%e8%88%87css-5","status":"publish","type":"post","link":"https:\/\/fromideatocreation.com\/?p=1573","title":{"rendered":"\u3010NEXT.JS \u7cfb\u5217\u3011\u8cc7\u7522\u3001\u5f8c\u8a2d\u8cc7\u6599\u8207CSS 5"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Layout \u5143\u4ef6<\/h2>\n\n\n\n<p>\u9996\u5148\uff0c\u8b93\u6211\u5011\u5efa\u7acb\u4e00\u500b <strong>Layout<\/strong> \u5143\u4ef6\uff0c\u5b83\u5c07\u5728\u6240\u6709\u9801\u9762\u4e4b\u9593\u5171\u4eab\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5efa\u7acb\u4e00\u500b\u540d\u70ba <code>components<\/code> \u7684\u9802\u5c64\u76ee\u9304\u3002<\/li>\n\n\n\n<li>\u5728 <code>components<\/code> \u5167\u90e8\uff0c\u5efa\u7acb\u4e00\u500b\u540d\u70ba <code>layout.js<\/code> \u7684\u6587\u4ef6\uff0c\u5176\u5167\u5bb9\u5982\u4e0b\uff1a<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">export default function Layout({ children }) {\n  return &lt;div&gt;{children}&lt;\/div&gt;;\n}<\/code><\/pre>\n\n\n\n<p>\u7136\u5f8c\uff0c\u6253\u958b <code>pages\/posts\/first-post.js<\/code>\uff0c\u70ba <code>Layout<\/code> \u5143\u4ef6\u6dfb\u52a0\u532f\u5165\uff0c\u4e26\u5c07\u5176\u8a2d\u70ba\u6700\u5916\u5c64\u5143\u4ef6\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">import Head from 'next\/head';\nimport Link from 'next\/link';\nimport Layout from '..\/..\/components\/layout';\n\nexport default function FirstPost() {\n  return (\n    &lt;Layout&gt;\n      &lt;Head&gt;\n        &lt;title&gt;First Post&lt;\/title&gt;\n      &lt;\/Head&gt;\n      &lt;h1&gt;First Post&lt;\/h1&gt;\n      &lt;h2&gt;\n        &lt;Link href=\"\/\"&gt;\n          &lt;a&gt;Back to home&lt;\/a&gt;\n        &lt;\/Link&gt;\n      &lt;\/h2&gt;\n    &lt;\/Layout&gt;\n  );\n}<\/code><\/pre>\n\n\n\n<div style=\"height:24px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u6dfb\u52a0 CSS<\/h2>\n\n\n\n<p>\u73fe\u5728\uff0c\u8b93\u6211\u5011\u70ba Layout \u5143\u4ef6\u6dfb\u52a0\u4e00\u4e9b\u6a23\u5f0f\u3002 \u70ba\u6b64\uff0c\u6211\u5011\u5c07\u4f7f\u7528 <a href=\"https:\/\/nextjs.org\/docs\/basic-features\/built-in-css-support#adding-component-level-css\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"CSS Modules\">CSS Modules<\/a>\uff0c\u5b83\u5141\u8a31\u60a8\u5728 React \u5143\u4ef6\u4e2d\u5c0e\u5165 CSS \u6587\u4ef6\u3002<\/p>\n\n\n\n<p>\u5efa\u7acb\u4e00\u500b\u540d\u70ba <code>components\/layout.module.css<\/code> \u7684\u6587\u4ef6\uff0c\u5176\u5167\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"css\" class=\"language-css\">.container {\n  max-width: 36rem;\n  padding: 0 1rem;\n  margin: 3rem auto 6rem;\n}<\/code><\/pre>\n\n\n\n<p><strong>\u91cd\u8981\u63d0\u793a<\/strong>\uff1a\u8981\u4f7f\u7528 CSS \u6a21\u7d44\uff0cCSS \u6587\u4ef6\u540d\u5fc5\u9808\u4ee5 <code>.module.css<\/code> \u7d50\u5c3e\u3002<\/p>\n\n\n\n<p>\u8981\u5728 <code>components\/layout.js<\/code> \u4e2d\u4f7f\u7528\u9019\u500b <code>container<\/code>\uff0c\u4f60\u9700\u8981\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u532f\u5165 CSS \u6587\u4ef6\u4e26\u70ba\u5176\u6307\u5b9a\u540d\u7a31\uff0c\u4f8b\u5982 <code>styles<\/code><\/li>\n\n\n\n<li>\u4f7f\u7528 <code>styles.container<\/code> \u4f5c\u70ba <code>className<\/code><\/li>\n<\/ul>\n\n\n\n<p>\u6253\u958b <code>components\/layout.js<\/code> \u4e26\u5c07\u5176\u5167\u5bb9\u66ff\u63db\u70ba\u4ee5\u4e0b\u5167\u5bb9\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">import styles from '.\/layout.module.css';\n\nexport default function Layout({ children }) {\n  return &lt;div className={styles.container}&gt;{children}&lt;\/div&gt;;\n}<\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u60a8\u73fe\u5728\u8a2a\u554f <a href=\"http:\/\/localhost:3000\/posts\/first-post\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/localhost:3000\/posts\/first-post<\/a>\uff0c\u60a8\u61c9\u8a72\u6703\u770b\u5230\u6587\u672c\u73fe\u5728\u4f4d\u65bc\u5c45\u4e2d\u7684\u5bb9\u5668\u4e2d\uff1a<\/p>\n\n\n\n<div class=\"wp-block-qubely-image qubely-block-245de9\"><div class=\"qubely-block-image  qubely-image-layout-simple\"><div class=\"qubely-image-media qubely-vertical-alignment-center qubely-horizontal-alignment-center\"><figure><div class=\"qubely-image-container\"><img decoding=\"async\" class=\"qubely-image-image\" src=\"https:\/\/fromideatocreation.com\/wp-content\/uploads\/2022\/06\/layout.png\" alt=\"\"\/><\/div><\/figure><\/div><\/div><\/div>\n\n\n\n<div style=\"height:24px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u81ea\u52d5\u751f\u6210\u552f\u4e00\u7684 Class Names<\/h2>\n\n\n\n<p>\u73fe\u5728\uff0c\u5982\u679c\u60a8\u67e5\u770b\u700f\u89bd\u5668\u7684\u958b\u767c\u5de5\u5177\u4e2d\u7684 HTML\uff0c\u60a8\u6703\u6ce8\u610f\u5230 <code>Layout<\/code> \u5143\u4ef6\u5448\u73fe\u7684 <code>div<\/code> \u6709\u4e00\u500b\u985e\u4f3c\u65bc <code>layout_container__...<\/code> \u7684 class name\uff1a<\/p>\n\n\n\n<div class=\"wp-block-qubely-image qubely-block-07ef5c\"><div class=\"qubely-block-image  qubely-image-layout-simple\"><div class=\"qubely-image-media qubely-vertical-alignment-center qubely-horizontal-alignment-center\"><figure><div class=\"qubely-image-container\"><img decoding=\"async\" class=\"qubely-image-image\" src=\"https:\/\/fromideatocreation.com\/wp-content\/uploads\/2022\/06\/devtools.png\" alt=\"\"\/><\/div><\/figure><\/div><\/div><\/div>\n\n\n\n<p>\u9019\u5c31\u662f CSS \u6a21\u7d44\u6240\u505a\u7684\uff1a\u5b83\u6703<strong>\u81ea\u52d5\u751f\u6210\u552f\u4e00\u7684 class name<\/strong>\u3002 \u53ea\u8981\u4f60\u4f7f\u7528 CSS Modules\uff0c\u4f60\u5c31\u4e0d\u5fc5\u64d4\u5fc3 class name \u885d\u7a81\u3002<\/p>\n\n\n\n<p>\u6b64\u5916\uff0cNext.js \u7684\u7a0b\u5f0f\u78bc\u62c6\u5206\u529f\u80fd\u4e5f\u9069\u7528\u65bc CSS \u6a21\u7d44\u3002 \u5b83\u78ba\u4fdd\u70ba\u6bcf\u500b\u9801\u9762\u52a0\u8f09\u6700\u5c11\u91cf\u7684 CSS\u3002 \u9019\u5c0e\u81f4\u66f4\u5c0f\u7684\u7d91\u7d81\u5305\u5927\u5c0f\u3002<\/p>\n\n\n\n<p>CSS \u6a21\u7d44\u5728\u5efa\u69cb\u6642\u5f9e JavaScript \u7d91\u7d81\u5305\u4e2d\u63d0\u53d6\uff0c\u4e26\u751f\u6210\u7531 Next.js \u81ea\u52d5\u52a0\u8f09\u7684 <code>.css<\/code> \u6587\u4ef6\u3002<\/p>\n\n\n\n<p><a href=\"https:\/\/fromideatocreation.com\/archives\/1180\" title=\"\u4e0b\u4e00\u7bc0\">\u4e0b\u4e00\u7bc0<\/a>\u6211\u5011\u4f86\u804a\u804a\u5168\u57df\u6a23\u5f0f global css\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u73fe\u5728\uff0c\u8b93\u6211\u5011\u70ba Layout \u5143\u4ef6\u6dfb\u52a0\u4e00\u4e9b\u6a23\u5f0f\u3002 \u70ba\u6b64\uff0c\u6211\u5011\u5c07\u4f7f\u7528 CSS Modules\uff0c\u5b83\u5141\u8a31\u60a8\u5728 React \u5143\u4ef6\u4e2d\u5c0e\u5165 CSS \u6587\u4ef6\u3002<\/p>\n","protected":false},"author":1,"featured_media":1165,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"qubely_global_settings":"","qubely_interactions":"","inline_featured_image":false,"_ti_tpc_template_sync":false,"_ti_tpc_template_id":"","footnotes":""},"categories":[164,106],"tags":[116,163],"class_list":["post-1573","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-next-js","category-106","tag-css","tag-next-js"],"acf":[],"aioseo_notices":[],"qubely_featured_image_url":{"full":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download.png",720,454,false],"landscape":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download.png",720,454,false],"portraits":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-540x320.png",540,320,true],"thumbnail":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-150x150.png",150,150,true],"medium":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-300x189.png",300,189,true],"medium_large":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download.png",640,404,false],"large":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download.png",640,404,false],"1536x1536":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download.png",720,454,false],"2048x2048":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download.png",720,454,false],"qubely_landscape":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download.png",720,454,false],"qubely_portrait":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-540x320.png",540,320,true],"qubely_thumbnail":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-140x100.png",140,100,true],"nazare_single_thumb":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download.png",720,454,false],"nazare_post_card_thumb":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-480x454.png",480,454,true],"nazare_widget_thumb":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-100x100.png",100,100,true],"nazare_widget_first_thumb":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-350x206.png",350,206,true],"nazare_el_banner_left":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download.png",720,454,false],"nazare_el_banner_right":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-560x454.png",560,454,true],"nazare_el_post_400x376":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-400x376.png",400,376,true],"nazare_el_post_520x460":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-520x454.png",520,454,true],"nazare_el_post_500x335":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-500x335.png",500,335,true],"nazare_el_post_500x300":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-500x300.png",500,300,true],"nazare_el_post_655x640":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-655x454.png",655,454,true],"nazare_el_post_500x290":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-500x290.png",500,290,true],"nazare_el_post_416x278":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-416x278.png",416,278,true],"nazare_el_post_480x425":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-480x425.png",480,425,true],"nazare_el_post_635x640":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-635x454.png",635,454,true],"nazare_el_post_305x177":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-305x177.png",305,177,true],"nazare_el_post_400x400":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-400x400.png",400,400,true],"nazare_el_post_400x360":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-400x360.png",400,360,true],"nazare_el_post_416x416":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-416x416.png",416,416,true],"nazare_el_post_485x430":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-485x430.png",485,430,true],"nazare_el_post_700x467":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-700x454.png",700,454,true],"nazare_el_post_1000x581":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download.png",720,454,false],"nazare_post_1320x605":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download.png",720,454,false],"nazare_post_705x565":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-705x454.png",705,454,true],"nazare_post_400x265":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-400x265.png",400,265,true],"nazare_el_post_1248x630":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download.png",720,454,false],"woocommerce_thumbnail":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-300x300.png",300,300,true],"woocommerce_single":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-600x378.png",600,378,true],"woocommerce_gallery_thumbnail":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-100x100.png",100,100,true],"shop_catalog":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-300x300.png",300,300,true],"shop_single":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-600x378.png",600,378,true],"shop_thumbnail":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-100x100.png",100,100,true]},"qubely_author":{"display_name":"Wen","author_link":"https:\/\/fromideatocreation.com\/?author=1"},"qubely_comment":0,"qubely_category":"<a href=\"https:\/\/fromideatocreation.com\/?cat=164\" rel=\"category\">Next.js<\/a> <a href=\"https:\/\/fromideatocreation.com\/?cat=106\" rel=\"category\">\u6559\u5b78<\/a>","qubely_excerpt":"\u73fe\u5728\uff0c\u8b93\u6211\u5011\u70ba Layout \u5143\u4ef6\u6dfb\u52a0\u4e00\u4e9b\u6a23\u5f0f\u3002 \u70ba\u6b64\uff0c\u6211\u5011\u5c07\u4f7f\u7528 CSS Modules\uff0c\u5b83\u5141\u8a31\u60a8\u5728 Rea...","_links":{"self":[{"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=\/wp\/v2\/posts\/1573","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1573"}],"version-history":[{"count":1,"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=\/wp\/v2\/posts\/1573\/revisions"}],"predecessor-version":[{"id":1626,"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=\/wp\/v2\/posts\/1573\/revisions\/1626"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=\/wp\/v2\/media\/1165"}],"wp:attachment":[{"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}