{"id":53105,"date":"2024-12-03T11:40:54","date_gmt":"2024-12-03T03:40:54","guid":{"rendered":"https:\/\/fwq.ai\/blog\/53105\/"},"modified":"2024-12-03T11:40:54","modified_gmt":"2024-12-03T03:40:54","slug":"react%e4%b8%ad%e5%a6%82%e4%bd%95%e4%b8%bamap%e5%be%aa%e7%8e%af%e7%94%9f%e6%88%90%e7%9a%84div%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\/53105\/","title":{"rendered":"React\u4e2d\u5982\u4f55\u4e3amap\u5faa\u73af\u751f\u6210\u7684div\u5143\u7d20\u6dfb\u52a0\u884c\u53f7\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>React\u4e2d\u5982\u4f55\u4e3amap\u5faa\u73af\u751f\u6210\u7684div\u5143\u7d20\u6dfb\u52a0\u884c\u53f7\uff1f<\/h1>\n<p><span style=\"color: #222222;, sans-serif;background-color: #FFFFFF\">\u5404\u4f4d\u5c0f\u4f19\u4f34\u4eec\uff0c\u5927\u5bb6\u597d\u5440\uff01\u770b\u770b\u4eca\u5929\u6211\u53c8\u7ed9\u5404\u4f4d\u5e26\u6765\u4e86\u4ec0\u4e48\u6587\u7ae0\uff1f\u672c\u6587\u6807\u9898<span style=\"color: #222222;, sans-serif;background-color: #FFFFFF\">\u662f<\/span><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aReact\u4e2d\u5982\u4f55\u4e3amap\u5faa\u73af\u751f\u6210\u7684div\u5143\u7d20\u6dfb\u52a0\u884c\u53f7\uff1f\u300b<\/span>\uff0c\u5f88\u660e\u663e\u662f\u5173\u4e8e<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u7684\u6587\u7ae0\u54c8\u54c8\u54c8\uff0c\u5176\u4e2d\u5185\u5bb9\u4e3b\u8981\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\uff0c\u5982\u679c\u80fd\u5e2e\u5230\u4f60\uff0c\u89c9\u5f97\u5f88\u4e0d\u9519\u7684\u8bdd\uff0c\u6b22\u8fce\u5404\u4f4d\u591a\u591a\u70b9\u8bc4\u548c\u5206\u4eab\uff01<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241126\/17326206336745b1594a5aa.jpg\" class=\"aligncenter\" title=\"React\u4e2d\u5982\u4f55\u4e3amap\u5faa\u73af\u751f\u6210\u7684div\u5143\u7d20\u6dfb\u52a0\u884c\u53f7\uff1f\u63d2\u56fe\" alt=\"React\u4e2d\u5982\u4f55\u4e3amap\u5faa\u73af\u751f\u6210\u7684div\u5143\u7d20\u6dfb\u52a0\u884c\u53f7\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4e3amap\u5faa\u73af\u521b\u5efa\u7684div\u6dfb\u52a0\u884c\u53f7<\/strong><\/p>\n<p>\u5728react\u7ec4\u4ef6\u4e2d\uff0c\u7ecf\u5e38\u9700\u8981\u57fa\u4e8e\u4f20\u5165\u7684props\u6570\u636e\u521b\u5efa\u591a\u4e2a\u5c0f\u65b9\u683c\u3002\u6bd4\u5982\uff1a<\/p>\n<pre>&lt;div id=\"container\"&gt;\n{ itemdata.map((item, index) =&gt; (\n          &lt;div key={index} style={{ ... }} &gt; &lt;\/div&gt;\n        )) }\n&lt;\/div&gt;<\/pre>\n<p>\u6548\u679c\u5982\u4e0b\uff1a<\/p>\n<p>\u5728\u6b64\u57fa\u7840\u4e0a\uff0c\u6211\u4eec\u60f3\u8981\u7ed9container div\u6dfb\u52a0\u884c\u53f7\uff0c\u5c31\u50cf\u7f16\u8f91\u5668\u7f16\u8f91\u4ee3\u7801\u4e00\u6837\uff0c\u524d\u9762\u663e\u793a\u884c\u53f7\u3002\u8981\u5b9e\u73b0\u8fd9\u4e00\u9700\u6c42\uff0c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<p><strong>\u5c06\u5de6\u4fa7\u7684\u7d22\u5f15\u8bbe\u7f6e\u4e3aabsolute\uff0c\u53f3\u4fa7\u7684\u65b9\u5757\u8bbe\u7f6e\u4e3arelative\uff0c\u4e24\u8005\u7684\u7236\u5143\u7d20\u8bbe\u7f6e\u4e3aposition: relative \u4e14 overflow: hidden;<\/strong><\/p>\n<pre>.app {\n  overflow: hidden;\n  position: relative;\n}\n\n.left-box {\n  position: absolute;\n  left: 0;\n  top: 0;\n  \n  width: 19px;\n  overflow: hidden;\n}\n\n.right-box {\n  margin-left: 19px;\n}<\/pre>\n<pre>&lt;div className=\"App\"&gt;\n      &lt;div className=\"left-box\"&gt;\n        {indexData.map((item, index) =&amp;gt; (\n          &lt;div\n            key={index}\n            style={{\n              fontSize: \"9px\",\n              width: \"19px\",\n              height: \"20px\",\n              margin: \"2px\",\n            }}\n          &gt;\n            {index}\n          &lt;\/div&gt;\n        ))}\n      &lt;\/div&gt;\n      &lt;div className=\"right-box\"&gt;\n        {itemData.map((item, index) =&amp;gt; (\n          &lt;div\n            key={index}\n            style={{\n              display: \"inline-block\",\n              width: \"9px\",\n              height: \"9px\",\n              margin: \"2px\",\n              backgroundColor: item.selected ? \"green\" : \"lightgreen\",\n            }}\n          &gt;&lt;\/div&gt;\n        ))}\n      &lt;\/div&gt;\n    &lt;\/div&gt;<\/pre>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300aReact\u4e2d\u5982\u4f55\u4e3amap\u5faa\u73af\u751f\u6210\u7684div\u5143\u7d20\u6dfb\u52a0\u884c\u53f7\uff1f\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u7c73\u4e91\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   \u7535\u8111\u5fae\u4fe1\u53ef\u4ee5\u53d1\u670b\u53cb\u5708\u5417\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>React\u4e2d\u5982\u4f55\u4e3amap\u5faa\u73af\u751f\u6210\u7684div\u5143\u7d20\u6dfb\u52a0\u884c\u53f7\uff1f \u5404\u4f4d\u5c0f\u4f19\u4f34\u4eec\uff0c\u5927\u5bb6\u597d\u5440\uff01\u770b\u770b\u4eca\u5929\u6211\u53c8\u7ed9\u5404\u4f4d\u5e26\u6765\u4e86\u4ec0\u4e48\u6587\u7ae0\uff1f\u672c\u6587\u6807\u9898\u662f\u300aReact\u4e2d\u5982\u4f55\u4e3amap\u5faa\u73af\u751f\u6210\u7684div\u5143\u7d20\u6dfb\u52a0\u884c\u53f7\uff1f\u300b\uff0c\u5f88\u660e\u663e\u662f\u5173\u4e8e\u6587\u7ae0\u7684\u6587\u7ae0\u54c8\u54c8\u54c8\uff0c\u5176\u4e2d\u5185\u5bb9\u4e3b\u8981\u4f1a\u6d89\u53ca\u5230\u7b49\u7b49\uff0c\u5982\u679c\u80fd\u5e2e\u5230\u4f60\uff0c\u89c9\u5f97\u5f88\u4e0d\u9519\u7684\u8bdd\uff0c\u6b22\u8fce\u5404\u4f4d\u591a\u591a\u70b9\u8bc4\u548c\u5206\u4eab\uff01 \u5982\u4f55\u4e3amap\u5faa\u73af\u521b\u5efa\u7684div\u6dfb\u52a0\u884c\u53f7 \u5728react\u7ec4\u4ef6\u4e2d\uff0c\u7ecf\u5e38\u9700\u8981\u57fa\u4e8e\u4f20\u5165\u7684props\u6570\u636e\u521b\u5efa\u591a\u4e2a\u5c0f\u65b9\u683c\u3002\u6bd4\u5982\uff1a &lt;div id=&#8221;container&#8221;&gt; { itemdata.map((item, index) =&gt; ( &lt;div key={index} style={{ &#8230; }} &gt; &lt;\/div&gt; )) } &lt;\/div&gt; \u6548\u679c\u5982\u4e0b\uff1a \u5728\u6b64\u57fa\u7840\u4e0a\uff0c\u6211\u4eec\u60f3\u8981\u7ed9container div\u6dfb\u52a0\u884c\u53f7\uff0c\u5c31\u50cf\u7f16\u8f91\u5668\u7f16\u8f91\u4ee3\u7801\u4e00\u6837\uff0c\u524d\u9762\u663e\u793a\u884c\u53f7\u3002\u8981\u5b9e\u73b0\u8fd9\u4e00\u9700\u6c42\uff0c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a \u5c06\u5de6\u4fa7\u7684\u7d22\u5f15\u8bbe\u7f6e\u4e3aabsolute\uff0c\u53f3\u4fa7\u7684\u65b9\u5757\u8bbe\u7f6e\u4e3arelative\uff0c\u4e24\u8005\u7684\u7236\u5143\u7d20\u8bbe\u7f6e\u4e3aposition: relative \u4e14 overflow: hidden; .app { overflow: hidden; position: relative; } .left-box { position: absolute; left: 0; top: 0; width: 19px; overflow: hidden; } .right-box { margin-left: 19px; } &lt;div [&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-53105","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53105","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=53105"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53105\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=53105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=53105"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=53105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}