{"id":6119,"date":"2026-04-28T13:42:43","date_gmt":"2026-04-28T06:42:43","guid":{"rendered":"https:\/\/dev.artru.net\/?p=6119"},"modified":"2026-04-28T13:52:42","modified_gmt":"2026-04-28T06:52:42","slug":"tong-hop-css-thay-the-javascript","status":"publish","type":"post","link":"https:\/\/artru.net\/zh\/tong-hop-css-thay-the-javascript\/","title":{"rendered":"\u518d\u89c1 JavaScript\uff1a2026 \u5e74\u5c06\u53d6\u4ee3 JS \u7684 CSS \u7279\u6027\u6c47\u603b"},"content":{"rendered":"<h2 class=\"wp-block-heading\">Popover API\uff1a\u65e0\u9700 JavaScript \u5373\u53ef\u521b\u5efa\u5f39\u51fa\u7a97\u53e3\u548c\u5bf9\u8bdd\u6846\u3002<\/h2>\n\n\n\n<p>\u4ee5\u524d\uff0c\u8981\u521b\u5efa\u6a21\u6001\u7a97\u53e3\u6216\u83dc\u5355\uff0c\u9700\u8981\u4f7f\u7528 JavaScript \u6765\u5904\u7406\u4e8b\u4ef6\u3002 <code data-no-translation=\"\" data-no-auto-translation=\"\">click<\/code>, \u56fd\u5bb6\u7ba1\u7406 <code data-no-translation=\"\" data-no-auto-translation=\"\">display: block\/none<\/code> \u5e76\u80fd\u5904\u7406\u70b9\u51fb\u5916\u90e8\u533a\u57df\u65f6\u7684\u5173\u95ed\u64cd\u4f5c\u3002\u5f39\u51fa\u6846 API \u4f1a\u81ea\u52a8\u5904\u7406\u6240\u6709\u8fd9\u4e9b\u64cd\u4f5c\u3002.<\/p>\n\n\n\n<p>\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\" data-no-translation=\"\" data-no-auto-translation=\"\"><code data-no-translation=\"\" data-no-auto-translation=\"\">&lt;button popovertarget=\"info-box\">Xem chi ti\u1ebft&lt;\/button>\n\n&lt;div id=\"info-box\" popover>\n  &lt;h3>Th\u00f4ng b\u00e1o quan tr\u1ecdng&lt;\/h3>\n  &lt;p>B\u1ea1n \u0111\u00e3 m\u1edf pop-up n\u00e0y ho\u00e0n to\u00e0n b\u1eb1ng CSS!&lt;\/p>\n  &lt;button popovertarget=\"info-box\" popovertargetaction=\"hide\">\u0110\u00f3ng&lt;\/button>\n&lt;\/div><\/code><\/pre>\n\n\n\n<p><strong>\u4f18\u52bf\uff1a<\/strong> \u81ea\u52a8\u5bc6\u94a5\u652f\u6301 <code data-no-translation=\"\" data-no-auto-translation=\"\">Esc<\/code> \u5173\u95ed\u548c\u673a\u5236 <code data-no-translation=\"\" data-no-auto-translation=\"\">\"Light Dismiss\"<\/code> \uff08\u6309\u5916\u4fa7\u952e\u5173\u95ed\uff09\u3002.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u951a\u70b9\u5b9a\u4f4d\uff1a\u5b9a\u4f4d\u5de5\u5177\u63d0\u793a\u548c\u4e0b\u62c9\u83dc\u5355<\/h2>\n\n\n\n<p>\u6211\u4eec\u4f7f\u7528JS\uff08\u4f5c\u4e3a\u5e93\uff09\u7684\u6700\u5927\u539f\u56e0\u4e4b\u4e00\u662f\u2026\u2026 <code data-no-translation=\"\" data-no-auto-translation=\"\">Popper.js<\/code> \u597d\u7684 <code data-no-translation=\"\" data-no-auto-translation=\"\">Floating UI<\/code>) \u7528\u4e8e\u8ba1\u7b97\u4e0b\u62c9\u83dc\u5355\u7684\u4f4d\u7f6e\uff0c\u4f7f\u5176\u4e0d\u4f1a\u8d85\u51fa\u5c4f\u5e55\u8303\u56f4\u3002. <code data-no-translation=\"\" data-no-auto-translation=\"\">Anchor Positioning<\/code> \u8fd9\u662f\u53e6\u4e00\u79cd\u89e3\u51b3\u65b9\u6848\u3002.<\/p>\n\n\n\n<p>\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\" data-no-translation=\"\" data-no-auto-translation=\"\"><code data-no-translation=\"\" data-no-auto-translation=\"\">\/* G\u00e1n t\u00ean cho ph\u1ea7n t\u1eed g\u1ed1c *\/\n.anchor-button {\n  anchor-name: --nav-menu;\n}\n\n\/* K\u1ebft n\u1ed1i menu v\u1edbi n\u00fat g\u1ed1c *\/\n.dropdown-menu {\n  position: absolute;\n  position-anchor: --nav-menu;\n  \/* \u0110\u1ecbnh v\u1ecb: N\u1eb1m d\u01b0\u1edbi n\u00fat v\u00e0 c\u0103n l\u1ec1 ph\u1ea3i *\/\n  position-area: bottom span-right;\n  margin-top: 8px;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u6eda\u52a8\u9a71\u52a8\u52a8\u753b\uff1a\u6d41\u7545\u7684\u9875\u9762\u6eda\u52a8\u6548\u679c<\/h2>\n\n\n\n<p>\u521b\u5efa\u6eda\u52a8\u65f6\u7684\u8fdb\u5ea6\u6761\u6548\u679c\u6216\u89c6\u5dee\u6548\u679c\u901a\u5e38\u4f1a\u6d88\u8017\u5927\u91cf JS \u8d44\u6e90\uff08\u56e0\u4e3a\u5b83\u5fc5\u987b\u76d1\u542c\u6eda\u52a8\u4e8b\u4ef6\uff09\u3002 <code data-no-translation=\"\" data-no-auto-translation=\"\">scroll<\/code> \uff08\u6301\u7eed\u5730\uff09\u3002CSS \u73b0\u5728\u6709 <code data-no-translation=\"\" data-no-auto-translation=\"\">scroll-timeline<\/code>.<\/p>\n\n\n\n<p>\u793a\u4f8b\uff1a\u6587\u7ae0\u9605\u8bfb\u8fdb\u5ea6\u6761<\/p>\n\n\n\n<pre class=\"wp-block-code\" data-no-translation=\"\" data-no-auto-translation=\"\"><code data-no-translation=\"\" data-no-auto-translation=\"\">@keyframes grow-progress {\n  from { transform: scaleX(0); }\n  to { transform: scaleX(1); }\n}\n\n.progress-bar {\n  position: fixed;\n  top: 0; left: 0;\n  width: 100%; height: 5px;\n  background: gold;\n  transform-origin: 0 50%;\n  \/* Li\u00ean k\u1ebft animation v\u1edbi vi\u1ec7c cu\u1ed9n trang *\/\n  animation: grow-progress auto linear;\n  animation-timeline: scroll();\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5bb9\u5668\u67e5\u8be2\uff1a\u66ff\u6362\u7ec4\u4ef6\u7684\u5a92\u4f53\u67e5\u8be2<\/h2>\n\n\n\n<p>\u4e0e\u5176\u6839\u636e\u5c4f\u5e55\u5c3a\u5bf8\uff08\u5a92\u4f53\u67e5\u8be2\uff09\u6539\u53d8\u754c\u9762\uff0c\u6211\u4eec\u53ef\u4ee5\u6839\u636e\u5bb9\u5668\u672c\u8eab\u7684\u5927\u5c0f\u6765\u6539\u53d8\u754c\u9762\u3002\u8fd9\u4f7f\u5f97\u7ec4\u4ef6\u66f4\u52a0\u7075\u6d3b\uff0c\u800c\u65e0\u9700\u4f7f\u7528 `&lt;div&gt;` \u6807\u7b7e\u3002 <code data-no-translation=\"\" data-no-auto-translation=\"\">ResizeObserver<\/code> \u5728JS\u4e2d\u3002.<\/p>\n\n\n\n<p>\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\" data-no-translation=\"\" data-no-auto-translation=\"\"><code data-no-translation=\"\" data-no-auto-translation=\"\">.container {\n  container-type: inline-size;\n}\n\n\/* Khi container r\u1ed9ng h\u01a1n 500px, chuy\u1ec3n sang giao di\u1ec7n 2 c\u1ed9t *\/\n@container (min-width: 500px) {\n  .card {\n    display: flex;\n    gap: 20px;\n  }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5f97\u51fa\u7ed3\u8bba<\/h2>\n\n\n\n<p>\u4ece JavaScript \u8f6c\u5411 CSS \u4e0d\u4ec5\u4ec5\u662f\u4e00\u79cd\u8d8b\u52bf\uff0c\u66f4\u662f\u4e3a\u4e86\u4f18\u5316\u6700\u7ec8\u7528\u6237\u4f53\u9a8c\u3002\u901a\u8fc7\u5229\u7528\u6d4f\u89c8\u5668\u5185\u7f6e\u529f\u80fd\uff0c\u60a8\u53ef\u4ee5\u8ba9\u7f51\u7ad9\u52a0\u8f7d\u66f4\u5feb\u3001\u66f4\u6d41\u7545\uff0c\u5e76\u6700\u5927\u9650\u5ea6\u5730\u51cf\u5c11\u811a\u672c\u51b2\u7a81\u3002.<\/p>\n\n\n\n<p>\u53c2\u8003\u6765\u6e90\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"7 \u4e2a\u8ba9\u4f60\u60ca\u53f9\u4e0d\u5df2\u7684 CSS \u6280\u5de7\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/Ol62e-dWu0E?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>","protected":false},"excerpt":{"rendered":"<p>Popover API: L\u00e0m Pop-up v\u00e0 Dialog kh\u00f4ng c\u1ea7n JS Tr\u01b0\u1edbc \u0111\u00e2y, \u0111\u1ec3 l\u00e0m m\u1ed9t c\u1eeda s\u1ed5 modal hay menu, b\u1ea1n c\u1ea7n JS \u0111\u1ec3 b\u1eaft s\u1ef1 ki\u1ec7n click, qu\u1ea3n l\u00fd tr\u1ea1ng [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[113],"tags":[],"class_list":["post-6119","post","type-post","status-publish","format-standard","hentry","category-css"],"_links":{"self":[{"href":"https:\/\/artru.net\/zh\/wp-json\/wp\/v2\/posts\/6119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/artru.net\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/artru.net\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/artru.net\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/artru.net\/zh\/wp-json\/wp\/v2\/comments?post=6119"}],"version-history":[{"count":0,"href":"https:\/\/artru.net\/zh\/wp-json\/wp\/v2\/posts\/6119\/revisions"}],"wp:attachment":[{"href":"https:\/\/artru.net\/zh\/wp-json\/wp\/v2\/media?parent=6119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artru.net\/zh\/wp-json\/wp\/v2\/categories?post=6119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artru.net\/zh\/wp-json\/wp\/v2\/tags?post=6119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}