{"id":27611,"date":"2024-11-24T16:38:57","date_gmt":"2024-11-24T08:38:57","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27611\/"},"modified":"2024-11-24T16:38:57","modified_gmt":"2024-11-24T08:38:57","slug":"%e5%a6%82%e4%bd%95%e4%b8%ba-react-%e5%be%aa%e7%8e%af%e5%88%9b%e5%bb%ba%e7%9a%84-div-%e5%85%83%e7%b4%a0%e6%b7%bb%e5%8a%a0%e8%a1%8c%e5%8f%b7%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27611\/","title":{"rendered":"\u5982\u4f55\u4e3a React \u5faa\u73af\u521b\u5efa\u7684 div \u5143\u7d20\u6dfb\u52a0\u884c\u53f7\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173129653380982.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4e3a React \u5faa\u73af\u521b\u5efa\u7684 div \u5143\u7d20\u6dfb\u52a0\u884c\u53f7\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4e3a React \u5faa\u73af\u521b\u5efa\u7684 div \u5143\u7d20\u6dfb\u52a0\u884c\u53f7\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4e3a react \u5faa\u73af\u521b\u5efa\u7684 div \u6dfb\u52a0\u884c\u53f7\uff1f<\/strong><\/p>\n<p>\u4e3a\u4e86\u7ed9\u57fa\u4e8e map \u5faa\u73af\u521b\u5efa\u7684 div \u6dfb\u52a0\u884c\u53f7\uff0c\u6211\u4eec\u53ef\u4ee5\u5229\u7528  \u5e03\u5c40\u6765\u5b9e\u73b0\u3002<\/p>\n<p>\u9996\u5148\uff0c\u4e3a div \u6dfb\u52a0\u4e00\u4e2a\u5bb9\u5668\u5143\u7d20\uff0c\u79f0\u4e3a &#8220;contner&#8221;\u3002\u628a &#8220;container&#8221; \u8bbe\u7f6e\u4e3a\uff0c\u5e76\u542f\u7528\u6ea2\u51fa\u9690\u85cf\uff0c\u4ee5\u4fbf\u8d85\u51fa\u5bb9\u5668\u8303\u56f4\u7684\u5143\u7d20\u88ab\u622a\u65ad\u3002\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>.container {\n  position: relative;\n  overflow: hidden;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a &#8220;index-row&#8221; \u7684\u5143\u7d20\uff0c\u5e76\u5c06\u5b83\u5b9a\u4f4d\u5728 &#8220;container&#8221; \u7684\u5de6\u8fb9\u3002\u628a &#8220;index-row&#8221; \u8bbe\u7f6e\u4e3a\uff0c\u8fd9\u6837\u5b83\u5c31\u53ef\u4ee5\u8986\u76d6\u5728 &#8220;container&#8221; \u4e0a\u3002\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>.index-row {\n  position: absolute;\n  left: 0;\n  top: 0;\n  width: 20px;\n  overflow: hidden;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6700\u540e\uff0c\u4f7f\u7528 map \u5faa\u73af\u5728 &#8220;index-row&#8221; \u4e2d\u521b\u5efa\u884c\u53f7\u3002\u8bbe\u7f6e\u6bcf\u4e2a\u884c\u53f7\u7684\u6837\u5f0f\uff0c\u5305\u62ec\u5b57\u53f7\u3001\u884c\u9ad8\u548c\u8fb9\u8ddd\u3002\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>const indexData = new Array(20).fill(0);\n\nreturn (\n  &lt;div className=\"container\"&gt;\n    &lt;div className=\"index-row\"&gt;\n      {indexData.map((item, index) =&gt; (\n        &lt;div key={index} style={{ fontSize: \"9px\", width: \"19px\", height: \"20px\", margin: \"2px\" }}&gt;\n          {index}\n        &lt;\/div&gt;\n      ))}\n    &lt;\/div&gt;\n    &lt;div className=\"right-box\"&gt;\n      {itemData.map((item, index) =&gt; (\n        &lt;div key={index} style={{ \/* \u6837\u5f0f *\/ }}&gt;&lt;\/div&gt;\n      ))}\n    &lt;\/div&gt;\n  &lt;\/div&gt;\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u6837\uff0c\u4f60\u53ef\u4ee5\u5728 react \u5faa\u73af\u521b\u5efa\u7684 div \u4e2d\u5b9e\u73b0\u884c\u53f7\u663e\u793a\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4e3a React \u5faa\u73af\u521b\u5efa\u7684 div \u5143\u7d20\u6dfb\u52a0\u884c\u53f7\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>\u5982\u4f55\u4e3a react \u5faa\u73af\u521b\u5efa\u7684 div \u6dfb\u52a0\u884c\u53f7\uff1f \u4e3a\u4e86\u7ed9\u57fa\u4e8e map \u5faa\u73af\u521b\u5efa\u7684 div \u6dfb\u52a0\u884c\u53f7\uff0c\u6211\u4eec\u53ef\u4ee5\u5229\u7528 \u5e03\u5c40\u6765\u5b9e\u73b0\u3002 \u9996\u5148\uff0c\u4e3a div \u6dfb\u52a0\u4e00\u4e2a\u5bb9\u5668\u5143\u7d20\uff0c\u79f0\u4e3a &#8220;contner&#8221;\u3002\u628a &#8220;container&#8221; \u8bbe\u7f6e\u4e3a\uff0c\u5e76\u542f\u7528\u6ea2\u51fa\u9690\u85cf\uff0c\u4ee5\u4fbf\u8d85\u51fa\u5bb9\u5668\u8303\u56f4\u7684\u5143\u7d20\u88ab\u622a\u65ad\u3002\u5982\u4e0b\u6240\u793a\uff1a .container { position: relative; overflow: hidden; } \u767b\u5f55\u540e\u590d\u5236 \u63a5\u4e0b\u6765\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a &#8220;index-row&#8221; \u7684\u5143\u7d20\uff0c\u5e76\u5c06\u5b83\u5b9a\u4f4d\u5728 &#8220;container&#8221; \u7684\u5de6\u8fb9\u3002\u628a &#8220;index-row&#8221; \u8bbe\u7f6e\u4e3a\uff0c\u8fd9\u6837\u5b83\u5c31\u53ef\u4ee5\u8986\u76d6\u5728 &#8220;container&#8221; \u4e0a\u3002\u5982\u4e0b\u6240\u793a\uff1a .index-row { position: absolute; left: 0; top: 0; width: 20px; overflow: hidden; } \u767b\u5f55\u540e\u590d\u5236 \u6700\u540e\uff0c\u4f7f\u7528 map \u5faa\u73af\u5728 &#8220;index-row&#8221; \u4e2d\u521b\u5efa\u884c\u53f7\u3002\u8bbe\u7f6e\u6bcf\u4e2a\u884c\u53f7\u7684\u6837\u5f0f\uff0c\u5305\u62ec\u5b57\u53f7\u3001\u884c\u9ad8\u548c\u8fb9\u8ddd\u3002\u5982\u4e0b\u6240\u793a\uff1a const indexData [&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-27611","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27611","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=27611"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27611\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27611"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27611"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27611"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}