{"id":1192,"date":"2024-11-10T13:02:03","date_gmt":"2024-11-10T05:02:03","guid":{"rendered":"https:\/\/fwq.ai\/blog\/1192\/"},"modified":"2024-11-10T13:02:03","modified_gmt":"2024-11-10T05:02:03","slug":"react-%e5%b5%8c%e5%a5%97%e7%bb%84%e4%bb%b6%e7%9a%84-css-%e4%bf%ae%e9%a5%b0%e4%bc%9a%e5%bd%b1%e5%93%8d%e5%86%85%e9%83%a8%e7%bb%84%e4%bb%b6%e5%90%97%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/1192\/","title":{"rendered":"React \u5d4c\u5957\u7ec4\u4ef6\u7684 CSS \u4fee\u9970\u4f1a\u5f71\u54cd\u5185\u90e8\u7ec4\u4ef6\u5417\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173028979753902.jpg\" class=\"aligncenter\" title=\"React \u5d4c\u5957\u7ec4\u4ef6\u7684 CSS \u4fee\u9970\u4f1a\u5f71\u54cd\u5185\u90e8\u7ec4\u4ef6\u5417\uff1f\u63d2\u56fe\" alt=\"React \u5d4c\u5957\u7ec4\u4ef6\u7684 CSS \u4fee\u9970\u4f1a\u5f71\u54cd\u5185\u90e8\u7ec4\u4ef6\u5417\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5d4c\u5957\u7ec4\u4ef6\u7684  \u4fee\u9970\u4f1a\u4e0d\u4f1a\u5f71\u54cd\u5185\u90e8\u7ec4\u4ef6\uff1f<\/strong><\/p>\n<p>\u5982\u679c\u4f60\u6709\u4e00\u4e2a\u50cf\u4e0b\u9762\u8fd9\u6837\u5d4c\u5957\u7684 react \u7ec4\u4ef6\uff1a<\/p>\n<pre>&lt;componenta&gt;\n  &lt;componentb&gt;\n  &lt;\/componentb&gt;\n&lt;\/componenta&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u90a3\u4e48\uff0c\u5bf9 componenta \u8bbe\u7f6e css \u5c5e\u6027\u662f\u5426\u4f1a\u6e17\u900f\u5230 componentb \u4e2d\u5462\uff1f<\/p>\n<p><strong>\u7b54\u6848\u662f\uff1a\u4e0d\u4f1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>react \u4f7f\u7528 css \u6a21\u5757\u548c css-in-js \u7b49\u6280\u672f\u6765\u9632\u6b62 css \u6e17\u900f\u3002\u8fd9\u4e9b\u6280\u672f\u901a\u8fc7\u751f\u6210\u968f\u673a\u5b57\u7b26\u4e32\u6765\u4e3a\u6bcf\u4e2a\u7ec4\u4ef6\u521b\u5efa\u552f\u4e00\u7684 css \u89c4\u5219\u3002\u56e0\u6b64\uff0c\u5bf9 componenta \u65bd\u52a0\u7684 css \u5c5e\u6027\u5c06\u4e0d\u4f1a\u5f71\u54cd componentb \u7684\u6837\u5f0f\u3002<\/p>\n<p>\u8bf7\u53c2\u9605\u4ee3\u7801\u793a\u4f8b\uff0c\u5176\u4e2d componenta \u5177\u6709\u4e00\u4e2a\u7ea2\u8272\u8fb9\u6846\uff0c\u800c componentb \u5177\u6709\u4e00\u4e2a\u84dd\u8272\u80cc\u666f\uff1a<\/p>\n<pre>const componenta = styled.div`\n  border: 1px solid red;\n`;\n\nconst componentb = styled.div`\n  background-color: blue;\n`;\n\nreactdom.render(\n  &lt;componenta&gt;\n    &lt;componentb&gt;hello world&lt;\/componentb&gt;\n  &lt;\/componenta&gt;,\n  document.getelementbyid('root')\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>&lt;div style=\"border: 1px solid red;\"&gt;\n  &lt;div style=\"background-color: blue;\"&gt;Hello World&lt;\/div&gt;\n&lt;\/div&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5982\u4f60\u6240\u89c1\uff0ccomponentb \u7684\u84dd\u8272\u80cc\u666f\u4e0d\u53d7 componenta \u7ea2\u8272\u8fb9\u6846\u7684\u5f71\u54cd\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fReact \u5d4c\u5957\u7ec4\u4ef6\u7684 CSS \u4fee\u9970\u4f1a\u5f71\u54cd\u5185\u90e8\u7ec4\u4ef6\u5417\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5d4c\u5957\u7ec4\u4ef6\u7684 \u4fee\u9970\u4f1a\u4e0d\u4f1a\u5f71\u54cd\u5185\u90e8\u7ec4\u4ef6\uff1f \u5982\u679c\u4f60\u6709\u4e00\u4e2a\u50cf\u4e0b\u9762\u8fd9\u6837\u5d4c\u5957\u7684 react \u7ec4\u4ef6\uff1a &lt;componenta&gt; &lt;componentb&gt; &lt;\/componentb&gt; &lt;\/componenta&gt; \u767b\u5f55\u540e\u590d\u5236 \u90a3\u4e48\uff0c\u5bf9 componenta \u8bbe\u7f6e css \u5c5e\u6027\u662f\u5426\u4f1a\u6e17\u900f\u5230 componentb \u4e2d\u5462\uff1f \u7b54\u6848\u662f\uff1a\u4e0d\u4f1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b react \u4f7f\u7528 css \u6a21\u5757\u548c css-in-js \u7b49\u6280\u672f\u6765\u9632\u6b62 css \u6e17\u900f\u3002\u8fd9\u4e9b\u6280\u672f\u901a\u8fc7\u751f\u6210\u968f\u673a\u5b57\u7b26\u4e32\u6765\u4e3a\u6bcf\u4e2a\u7ec4\u4ef6\u521b\u5efa\u552f\u4e00\u7684 css \u89c4\u5219\u3002\u56e0\u6b64\uff0c\u5bf9 componenta \u65bd\u52a0\u7684 css \u5c5e\u6027\u5c06\u4e0d\u4f1a\u5f71\u54cd componentb \u7684\u6837\u5f0f\u3002 \u8bf7\u53c2\u9605\u4ee3\u7801\u793a\u4f8b\uff0c\u5176\u4e2d componenta \u5177\u6709\u4e00\u4e2a\u7ea2\u8272\u8fb9\u6846\uff0c\u800c componentb \u5177\u6709\u4e00\u4e2a\u84dd\u8272\u80cc\u666f\uff1a const componenta = styled.div` border: 1px solid red; `; const componentb = styled.div` background-color: blue; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-1192","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1192","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=1192"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1192\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=1192"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=1192"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=1192"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}