{"id":27683,"date":"2024-11-24T17:54:35","date_gmt":"2024-11-24T09:54:35","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27683\/"},"modified":"2024-11-24T17:54:35","modified_gmt":"2024-11-24T09:54:35","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-react-%e4%b8%ad%e5%b0%81%e8%a3%85-tooltip-%e7%bb%84%e4%bb%b6%e6%97%b6%ef%bc%8c%e8%ae%a9%e4%bc%aa%e5%85%83%e7%b4%a0%e7%9a%84%e5%ae%bd%e5%ba%a6%e9%80%82%e5%ba%94%e6%96%87","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27683\/","title":{"rendered":"\u5982\u4f55\u5728 React \u4e2d\u5c01\u88c5 Tooltip \u7ec4\u4ef6\u65f6\uff0c\u8ba9\u4f2a\u5143\u7d20\u7684\u5bbd\u5ea6\u9002\u5e94\u6587\u5b57\u5185\u5bb9\u5e76\u9650\u5236\u6700\u5927\u5bbd\u5ea6\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173130500419493.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5728 React \u4e2d\u5c01\u88c5 Tooltip \u7ec4\u4ef6\u65f6\uff0c\u8ba9\u4f2a\u5143\u7d20\u7684\u5bbd\u5ea6\u9002\u5e94\u6587\u5b57\u5185\u5bb9\u5e76\u9650\u5236\u6700\u5927\u5bbd\u5ea6\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5728 React \u4e2d\u5c01\u88c5 Tooltip \u7ec4\u4ef6\u65f6\uff0c\u8ba9\u4f2a\u5143\u7d20\u7684\u5bbd\u5ea6\u9002\u5e94\u6587\u5b57\u5185\u5bb9\u5e76\u9650\u5236\u6700\u5927\u5bbd\u5ea6\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u4f2a\u5143\u7d20\u9002\u5e94\u6587\u5b57\u5bbd\u5ea6\u5e76\u9650\u5236\u6700\u5927\u5bbd\u5ea6<\/strong><\/p>\n<p>\u5728 React \u4e2d\u5c01\u88c5 Tooltip \u7ec4\u4ef6\u65f6\uff0c\u6211\u4eec\u5e0c\u671b\u4f2a\u5143\u7d20\u7684\u5bbd\u5ea6\u9002\u5e94\u6587\u5b57\u5185\u5bb9\uff0c\u540c\u65f6\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\uff1a<\/p>\n<ul>\n<li>\u6587\u5b57\u5bbd\u5ea6\u5c0f\u4e8e\u6700\u5927\u5bbd\u5ea6\u65f6\u4e0d\u6362\u884c<\/li>\n<li>\u6587\u5b57\u5bbd\u5ea6\u5927\u4e8e\u6700\u5927\u5bbd\u5ea6\u65f6\u81ea\u52a8\u6362\u884c<\/li>\n<\/ul>\n<p>\u7136\u800c\uff0c\u4f7f\u7528 white-space: nowrap; \u6216 word-wrap: break-word; \u90fd\u4f1a\u5e26\u6765\u4e00\u4e9b\u95ee\u9898\u3002<\/p>\n<p><strong>\u5982\u4f55\u89e3\u51b3\uff1f<\/strong><\/p>\n<p>\u89e3\u51b3\u65b9\u6cd5\u662f\uff1a<\/p>\n<ol>\n<li><strong>\u8ba1\u7b97\u5143\u7d20\u7684\u521d\u59cb\u5bbd\u5ea6<\/strong><\/li>\n<\/ol>\n<p>\u4e3a\u4e86\u8ba1\u7b97 width: fit-content\uff0c\u6211\u4eec\u9700\u8981\u77e5\u9053\u5143\u7d20\u7684\u521d\u59cb\u5bbd\u5ea6\uff1a<\/p>\n<ul>\n<li>\u5982\u679c\u6700\u5927\u5185\u5bb9\u5bbd\u5ea6\u5927\u4e8e\u521d\u59cb\u5bbd\u5ea6\uff0c\u5143\u7d20\u5728\u521d\u59cb\u5bbd\u5ea6\u5904\u6362\u884c\uff0c\u8ba1\u7b97\u7ed3\u679c\u5c31\u662f\u8fd9\u4e2a\u5bbd\u5ea6\u3002<\/li>\n<li>\u5982\u679c\u6700\u5927\u5185\u5bb9\u5bbd\u5ea6\u5c0f\u4e8e\u521d\u59cb\u5bbd\u5ea6\uff0c\u8ba1\u7b97\u7ed3\u679c\u5c31\u662f\u6700\u5927\u5185\u5bb9\u5bbd\u5ea6\u3002<\/li>\n<\/ul>\n<ol>\n<li><strong>\u907f\u514d\u521d\u59cb\u5bbd\u5ea6\u5c0f\u4e8e\u6700\u5927\u5bbd\u5ea6<\/strong><\/li>\n<\/ol>\n<p>\u5982\u679c\u521d\u59cb\u5bbd\u5ea6\u5c0f\u4e8e\u6700\u5927\u5bbd\u5ea6\uff0c\u4e14\u6700\u5927\u5185\u5bb9\u5bbd\u5ea6\u5927\u4e8e\u6700\u5927\u5bbd\u5ea6\uff0c\u4f2a\u5143\u7d20\u4f1a\u5728\u521d\u59cb\u5bbd\u5ea6\u5904\u6362\u884c\uff0c\u800c\u4e0d\u662f\u5728\u6700\u5927\u5bbd\u5ea6\u65f6\u3002\u8fd9\u662f\u56e0\u4e3a\u4f2a\u5143\u7d20\u7684 left: 50%; \u5c5e\u6027\u4f7f\u5b83\u7684\u521d\u59cb\u5bbd\u5ea6\u53ea\u6709\u7236\u5143\u7d20\u5bbd\u5ea6\u7684\u4e00\u534a\u3002<\/p>\n<ol>\n<li><strong>\u8c03\u6574 Tooltip \u5e03\u5c40<\/strong><\/li>\n<\/ol>\n<p>\u5927\u591a\u6570 Tooltip \u5b9e\u73b0\u90fd\u5c06 tooltip-toggle \u548c tooltip \u5206\u522b\u653e\u5728\u4e24\u4e2a\u5143\u7d20\u4e0a\u3002tooltip \u91c7\u7528\uff0c\u76f8\u5bf9\u4e8e body\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u521d\u59cb\u5bbd\u5ea6\u8f83\u5927\uff0c\u4f2a\u5143\u7d20\u7684\u521d\u59cb\u5bbd\u5ea6\u5c31\u4e0d\u7528\u62c5\u5fc3\u5c0f\u4e8e\u6700\u5927\u5bbd\u5ea6\u4e86\u3002\u7136\u540e\u4f7f\u7528 popper.js \u7b49\u5e93\u8ba1\u7b97 inset\uff0c\u5c06\u5176\u5b9a\u4f4d\u5728 tooltip-toggle \u5468\u56f4\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5728 React \u4e2d\u5c01\u88c5 Tooltip \u7ec4\u4ef6\u65f6\uff0c\u8ba9\u4f2a\u5143\u7d20\u7684\u5bbd\u5ea6\u9002\u5e94\u6587\u5b57\u5185\u5bb9\u5e76\u9650\u5236\u6700\u5927\u5bbd\u5ea6\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>\u4f2a\u5143\u7d20\u9002\u5e94\u6587\u5b57\u5bbd\u5ea6\u5e76\u9650\u5236\u6700\u5927\u5bbd\u5ea6 \u5728 React \u4e2d\u5c01\u88c5 Tooltip \u7ec4\u4ef6\u65f6\uff0c\u6211\u4eec\u5e0c\u671b\u4f2a\u5143\u7d20\u7684\u5bbd\u5ea6\u9002\u5e94\u6587\u5b57\u5185\u5bb9\uff0c\u540c\u65f6\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\uff1a \u6587\u5b57\u5bbd\u5ea6\u5c0f\u4e8e\u6700\u5927\u5bbd\u5ea6\u65f6\u4e0d\u6362\u884c \u6587\u5b57\u5bbd\u5ea6\u5927\u4e8e\u6700\u5927\u5bbd\u5ea6\u65f6\u81ea\u52a8\u6362\u884c \u7136\u800c\uff0c\u4f7f\u7528 white-space: nowrap; \u6216 word-wrap: break-word; \u90fd\u4f1a\u5e26\u6765\u4e00\u4e9b\u95ee\u9898\u3002 \u5982\u4f55\u89e3\u51b3\uff1f \u89e3\u51b3\u65b9\u6cd5\u662f\uff1a \u8ba1\u7b97\u5143\u7d20\u7684\u521d\u59cb\u5bbd\u5ea6 \u4e3a\u4e86\u8ba1\u7b97 width: fit-content\uff0c\u6211\u4eec\u9700\u8981\u77e5\u9053\u5143\u7d20\u7684\u521d\u59cb\u5bbd\u5ea6\uff1a \u5982\u679c\u6700\u5927\u5185\u5bb9\u5bbd\u5ea6\u5927\u4e8e\u521d\u59cb\u5bbd\u5ea6\uff0c\u5143\u7d20\u5728\u521d\u59cb\u5bbd\u5ea6\u5904\u6362\u884c\uff0c\u8ba1\u7b97\u7ed3\u679c\u5c31\u662f\u8fd9\u4e2a\u5bbd\u5ea6\u3002 \u5982\u679c\u6700\u5927\u5185\u5bb9\u5bbd\u5ea6\u5c0f\u4e8e\u521d\u59cb\u5bbd\u5ea6\uff0c\u8ba1\u7b97\u7ed3\u679c\u5c31\u662f\u6700\u5927\u5185\u5bb9\u5bbd\u5ea6\u3002 \u907f\u514d\u521d\u59cb\u5bbd\u5ea6\u5c0f\u4e8e\u6700\u5927\u5bbd\u5ea6 \u5982\u679c\u521d\u59cb\u5bbd\u5ea6\u5c0f\u4e8e\u6700\u5927\u5bbd\u5ea6\uff0c\u4e14\u6700\u5927\u5185\u5bb9\u5bbd\u5ea6\u5927\u4e8e\u6700\u5927\u5bbd\u5ea6\uff0c\u4f2a\u5143\u7d20\u4f1a\u5728\u521d\u59cb\u5bbd\u5ea6\u5904\u6362\u884c\uff0c\u800c\u4e0d\u662f\u5728\u6700\u5927\u5bbd\u5ea6\u65f6\u3002\u8fd9\u662f\u56e0\u4e3a\u4f2a\u5143\u7d20\u7684 left: 50%; \u5c5e\u6027\u4f7f\u5b83\u7684\u521d\u59cb\u5bbd\u5ea6\u53ea\u6709\u7236\u5143\u7d20\u5bbd\u5ea6\u7684\u4e00\u534a\u3002 \u8c03\u6574 Tooltip \u5e03\u5c40 \u5927\u591a\u6570 Tooltip \u5b9e\u73b0\u90fd\u5c06 tooltip-toggle \u548c tooltip \u5206\u522b\u653e\u5728\u4e24\u4e2a\u5143\u7d20\u4e0a\u3002tooltip \u91c7\u7528\uff0c\u76f8\u5bf9\u4e8e body\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u521d\u59cb\u5bbd\u5ea6\u8f83\u5927\uff0c\u4f2a\u5143\u7d20\u7684\u521d\u59cb\u5bbd\u5ea6\u5c31\u4e0d\u7528\u62c5\u5fc3\u5c0f\u4e8e\u6700\u5927\u5bbd\u5ea6\u4e86\u3002\u7136\u540e\u4f7f\u7528 popper.js \u7b49\u5e93\u8ba1\u7b97 inset\uff0c\u5c06\u5176\u5b9a\u4f4d\u5728 tooltip-toggle \u5468\u56f4\u3002 \u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5728 React \u4e2d\u5c01\u88c5 Tooltip \u7ec4\u4ef6\u65f6\uff0c\u8ba9\u4f2a\u5143\u7d20\u7684\u5bbd\u5ea6\u9002\u5e94\u6587\u5b57\u5185\u5bb9\u5e76\u9650\u5236\u6700\u5927\u5bbd\u5ea6\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},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-27683","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27683","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=27683"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27683\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27683"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27683"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}