{"id":11727,"date":"2025-06-13T16:24:36","date_gmt":"2025-06-13T08:24:36","guid":{"rendered":"https:\/\/www.zhangxinxu.com\/wordpress\/?p=11727"},"modified":"2025-06-13T16:27:12","modified_gmt":"2025-06-13T08:27:12","slug":"css-scroll-button-marker","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2025\/06\/css-scroll-button-marker\/","title":{"rendered":"CSS ::scroll-button ::scroll-marker\u4f2a\u5143\u7d20\u53c8\u662f\u5e72\u561b\u7528\u7684\uff1f"},"content":{"rendered":"<p>by <a href=\"https:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=11727\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=11727<\/a><br \/>\n\u672c\u6587\u53ef\u5168\u6587\u8f6c\u8f7d\uff0c\u4f46\u9700\u8981\u4fdd\u7559\u539f\u4f5c\u8005\u3001\u51fa\u5904\u4ee5\u53ca\u6587\u4e2d\u94fe\u63a5\uff0cAI\u6293\u53d6\u4fdd\u7559\u539f\u6587\u5730\u5740\uff0c\u4efb\u4f55\u7f51\u7ad9\u5747\u53ef\u6458\u8981\u805a\u5408\uff0c\u5546\u7528\u8bf7\u8054\u7cfb\u6388\u6743\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202506\/2025-6-13_161945.jpeg\" width=\"160\" height=\"103\" alt=\"scroll snap \u6309\u94ae\u81ea\u5b9a\u4e49\u5c01\u9762\u56fe\" class=\"alignleft size-medium\" style=\"margin-right:12px;\" \/><\/p>\n<p>\u5148\u56de\u7b54\u9898\u76ee\u629b\u51fa\u7684\u95ee\u9898\uff0c\u4e00\u53e5\u8bdd\uff1a<\/p>\n<p><code>::scroll-button<\/code>\u53ef\u4ee5\u81ea\u5b9a\u4e49\u4e0a\u4e0b\u6216\u5de6\u53f3\u6eda\u52a8\u6309\u94ae\uff0c<code>::scroll-marker<\/code>\u53ef\u4ee5\u81ea\u5b9a\u4e49\u5207\u6362\u6309\u94ae\uff0c\u7528\u5728CSS Scroll Snap\u4ea4\u4e92\u573a\u666f\u4e0b\uff0c\u4ee5\u4fbf\u5b9e\u73b0\u5b8c\u6574\u7684Carousel\uff0cSlider\u7b49\u4ea4\u4e92\u6548\u679c\u3002<\/p>\n<h3>\u4e00\u3001\u4e00\u53cd\u5e38\u6001\uff0c\u5148\u4e0a\u6848\u4f8b<\/h3>\n<p>\u5148\u770b<code>::scroll-button()<\/code>\u4f2a\u5143\u7d20\u4f7f\u7528\u573a\u666f\uff0c\u53ef\u4ee5\u6a21\u62dfScroll Snap\u4e0a\u4e00\u9879\u548c\u4e0b\u4e00\u9879\u5207\u6362\u5c55\u793a\u6548\u679c\u3002<\/p>\n<p>\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/study\/202506\/css-scroll-button-demo.php\" rel=\"noopener\" target=\"_blank\">CSS ::scroll-button\u5b9e\u73b0slide\u5de6\u53f3\u5207\u6362demo<\/a><\/p>\n<p>\u53ef\u4ee5\u770b\u5230\u56fe\u7247slider\u5de6\u53f3\u6709\u5207\u6362\u6309\u94ae\uff0c\u70b9\u51fb\u7684\u65f6\u5019\uff0c\u56fe\u7247\u5c31\u4f1a\u5de6\u53f3\u6ed1\u52a8\uff0c\u975e\u5e38\u7684\u6d41\u7545\uff0c\u6574\u4e2a\u4ea4\u4e92\u8fc7\u7a0b\u6ca1\u6709\u4efb\u4f55JS\u7684\u53c2\u4e0e\u3002<\/p>\n<p>\u5982\u4e0bMP4\u5f55\u5c4f\u6240\u793a\uff08\u4e0d\u52a8\u70b9\u51fb\u64ad\u653e\uff09\uff1a<\/p>\n<p><video src='\/\/image.zhangxinxu.com\/video\/blog\/202506\/scroll-button.mp4' type=\"video\/mp4\" width=\"256\" height=\"196\" preload=\"auto\" muted autoplay autobuffer loop x-webkit-airplay=\"allow\" x5-video-player-type=\"h5\" x5-video-player-fullscreen=\"true\" x5-video-orientation=\"portraint\" webkit-playsinline=\"true\" playsinline=\"true\" \u200b\u200b\u200b\u200bposter=\"\/\/image.zhangxinxu.com\/image\/blog\/201806\/poster.png\"><\/video><\/p>\n<p>\u5176\u4e2d\u8fd8\u4f7f\u7528\u4e86\u951a\u70b9\u5b9a\u4f4d\u6280\u672f\uff0c\u6709\u5174\u8da3\u7684\u53ef\u4ee5\u53c2\u89c1\u201c<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/2024\/06\/css-anchor-positioning-api\/\">\u5168\u65b0\u7684CSS Anchor Positioning\u951a\u70b9\u5b9a\u4f4dAPI<\/a>\u201d\u8fd9\u7bc7\u6587\u7ae0\u3002<\/p>\n<h4>\u6838\u5fc3\u4ee3\u7801<\/h4>\n<p>\u5176\u4e2d\uff0cHTML\u7ed3\u6784\u6bd4\u8f83\u7b80\u5355\uff1a<\/p>\n<pre>&lt;zxx-slide&gt;\r\n  &lt;a href=\"###\"&gt;&lt;img src=\"ps1.jpg\"&gt;&lt;\/a&gt;\r\n  &lt;a href=\"###\"&gt;&lt;img src=\"ps2.jpg\"&gt;&lt;\/a&gt;\r\n  &lt;a href=\"###\"&gt;&lt;img src=\"ps3.jpg\"&gt;&lt;\/a&gt;\r\n  &lt;a href=\"###\"&gt;&lt;img src=\"ps4.jpg\"&gt;&lt;\/a&gt;\r\n&lt;\/zxx-slide&gt;<\/pre>\n<p>CSS\u6838\u5fc3\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff08\u5b8c\u6574\u4ee3\u7801<a href=\"https:\/\/www.zhangxinxu.com\/study\/202506\/css-scroll-button-demo.php\" rel=\"noopener\" target=\"_blank\">\u8bbf\u95eedemo<\/a>\u83b7\u53d6\uff09\uff1a<\/p>\n<pre>zxx-slide {\r\n  overflow: auto;\r\n  scrollbar-width: none;\r\n  overscroll-behavior-x: contain;\r\n  scroll-snap-type: x mandatory;\r\n  scroll-behavior: smooth;\r\n\r\n  a {\r\n    scroll-snap-align: start;\r\n  }\r\n}\r\n\r\nzxx-slide::scroll-button(left) {\r\n  content: \"\u25c4\";\r\n}\r\n\r\nzxx-slide::scroll-button(right) {\r\n  content: \"\u25ba\";\r\n}\r\nzxx-slide {\r\n  anchor-name: --myCarousel;\r\n}\r\n\r\nzxx-slide::scroll-button(*) {\r\n  position: absolute;\r\n  position-anchor: --myCarousel;\r\n}\r\nzxx-slide::scroll-button(*) {\r\n  align-self: anchor-center;\r\n}\r\nzxx-slide::scroll-button(left) {\r\n  right: calc(anchor(left) - 45px);\r\n}\r\n\r\nzxx-slide::scroll-button(right) {\r\n  left: calc(anchor(right) - 45px);\r\n}<\/pre>\n<p>\u4f7f\u7528\u4e86\u5f88\u591aCSS\u65b0\u7279\u6027\uff0c\u5982\u679c\u4e0d\u662f\u6301\u7eed\u5173\u6ce8CSS\u7684\u524d\u7aef\u5f00\u53d1\uff0c\u4e0a\u9762\u7684\u4ee3\u7801\u591a\u534a\u90fd\u5df2\u7ecf\u4e0d\u8ba4\u8bc6\u4e86\u3002<\/p>\n<h4>::scroll-button()\u4f2a\u5143\u7d20\u51fd\u6570\u8bed\u6cd5<\/h4>\n<p>\u652f\u6301\u7684\u53c2\u6570\u5305\u62ec\u4e0b\u9762\u8fd9\u4e9b\uff1a<\/p>\n<pre>::scroll-button(*) {}\r\n::scroll-button(left) {}\r\n::scroll-button(up) {}\r\n::scroll-button(right) {}\r\n::scroll-button(down) {}\r\n::scroll-button(block-end) {}\r\n::scroll-button(block-start) {}\r\n::scroll-button(inline-end) {}\r\n::scroll-button(inline-start) {}<\/pre>\n<p>\u6ce8\u610f\uff0c\u5782\u76f4\u8bbf\u95ee\u662fup\/down\uff0c\u800c\u4e0d\u662ftop\/bottom\u3002<\/p>\n<p>\u5e38\u89c4\u7684CSS\u5c5e\u6027\u90fd\u652f\u6301\uff0c\u56e0\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u81ea\u5982\u5730\u5bf9\u5207\u6362\u6309\u94ae\u8fdb\u884c\u6837\u5f0f\u81ea\u5b9a\u4e49\u3002<\/p>\n<h3>\u4e8c\u3001::scroll-marker\u4f7f\u7528\u6848\u4f8b<\/h3>\n<p><code>::scroll-marker<\/code>\u7684\u662f\u8981\u8981\u66f4\u590d\u6742\u4e9b\uff0c\u9700\u8981\u548c<code>scroll-marker-group<\/code>\u5c5e\u6027\u4ee5\u53ca<code>::scroll-marker-group<\/code>\u4f2a\u5143\u7d20\u914d\u5408\u4f7f\u7528\u3002<\/p>\n<p>\u8fd8\u662f\u901a\u8fc7\u6848\u4f8b\u5feb\u901f\u4e0a\u624b\u5427\u3002<\/p>\n<p>\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/study\/202506\/css-scroll-marker-demo.php\" rel=\"noopener\" target=\"_blank\">CSS ::scroll-marker\u5b9e\u73b0slide\u5e8f\u53f7\u5207\u6362demo<\/a><\/p>\n<p>\u9875\u9762\u6548\u679c\u5982\u4e0b\uff0c\u70b9\u51fb\u4e0b\u9762\u7684\u5e8f\u53f7\u6309\u94ae\uff0c\u56fe\u7247\u5c31\u4f1a\u5e73\u6ed1\u6eda\u52a8\u5230\u5bf9\u5e94\u7684\u4f4d\u7f6e\uff0c\u5982\u4e0b\u622a\u5c4f\u52a8\u753b\u6240\u793a\uff08\u4e0d\u64ad\u653e\u5c31\u201c\u6233\u201d\u4e00\u4e0b\uff09\uff1a<\/p>\n<p><video src='\/\/image.zhangxinxu.com\/video\/blog\/202506\/scroll-marker.mp4' type=\"video\/mp4\" width=\"256\" height=\"232\" preload=\"auto\" muted autoplay autobuffer loop x-webkit-airplay=\"allow\" x5-video-player-type=\"h5\" x5-video-player-fullscreen=\"true\" x5-video-orientation=\"portraint\" webkit-playsinline=\"true\" playsinline=\"true\" \u200b\u200b\u200b\u200bposter=\"\/\/image.zhangxinxu.com\/image\/blog\/201806\/poster.png\"><\/video><\/p>\n<p>\u5f88\u8d5e\uff0c\u5bf9\u4e0d\u5bf9\uff1f<\/p>\n<h4>\u6838\u5fc3\u4ee3\u7801<\/h4>\n<p>HTML\u548c\u4e0a\u9762demo\u4e00\u6837\uff0c\u4e3b\u8981\u770b\u4e0bCSS\u90e8\u5206\uff1a<\/p>\n<pre>zxx-slide {\r\n  display: flex;\r\n  overflow: auto;\r\n  scrollbar-width: none;\r\n  overscroll-behavior-x: contain;\r\n  scroll-snap-type: x mandatory;\r\n  scroll-behavior: smooth;\r\n  scroll-marker-group: after;\r\n\r\n  a {\r\n    scroll-snap-align: start;\r\n    counter-increment: markers;\r\n\r\n    &amp;::scroll-marker {\r\n      content: counter(markers);\r\n      \/*... *\/\r\n    }\r\n  }\r\n\r\n  ::scroll-marker:target-current {\r\n    background-color: #cd0000;\r\n    color: white;\r\n  }\r\n}\r\n\r\n::scroll-marker-group {\r\n  display: flex;\r\n  place-content: center;\r\n}<\/pre>\n<p>\u8fd9\u91cc\u51fa\u73b0\u4e86\u4e00\u4e2a\u65b0\u7684\u4f2a\u7c7b<code>:target-current<\/code>\uff0c\u8868\u793a\u5f53\u9009\u5339\u914d\u7684marker\u9009\u9879\u3002<\/p>\n<h4>scroll-marker-group\u5c5e\u6027<\/h4>\n<p><code>scroll-marker-group<\/code>\u5c5e\u6027\u7684\u4f5c\u7528\uff1a\u63a7\u5236\u5305\u542b<code>::scroll-marker-group<\/code>\u4f2a\u5143\u7d20\u7684\u6eda\u52a8\u5bb9\u5668\u662f\u5426\u751f\u6210\uff0c\u5982\u679c\u751f\u6210\uff0c\u4f4d\u7f6e\u662f\u524d\u8fd8\u662f\u540e\u3002<\/p>\n<p>\u4f7f\u7528\u793a\u610f\uff1a<\/p>\n<pre>\/* \u7d22\u5f15\u5e8f\u53f7\u7ec4\u5728\u6eda\u52a8\u5bb9\u5668\u524d\u9762 *\/\r\nscroll-marker-group: before;\r\n\/* \u7d22\u5f15\u5e8f\u53f7\u7ec4\u5728\u6eda\u52a8\u5bb9\u5668\u540e\u9762 *\/\r\nscroll-marker-group: after;\r\n\/* \u9ed8\u8ba4\u503c\uff0c\u4e0d\u663e\u793a\u7d22\u5f15\u5e8f\u53f7\u7ec4 *\/\r\nscroll-marker-group: none;<\/pre>\n<h4>::scroll-marker-group\u4f2a\u5143\u7d20<\/h4>\n<p><code>::scroll-marker<\/code>\u4f2a\u5143\u7d20\u7684\u7236\u7ea7\u5bb9\u5668\u5143\u7d20\uff0c\u63a7\u5236\u7d22\u5f15\u5e8f\u53f7\u6574\u4f53\u4f4d\u7f6e\u3001\u6837\u5f0f\u7528\u7684\u3002<\/p>\n<p>\u5177\u4f53\u4f7f\u7528\u53c2\u89c1\u4e0a\u9762\u7684\u6837\u5f0f\u9875\u9762\u3002<\/p>\n<h3>\u4e09\u3001\u517c\u5bb9\u6027\u4ee5\u53ca\u7ed3\u8bed\u82e5\u5e72<\/h3>\n<p>\u672c\u6587\u4ecb\u7ecd\u7684\u8fd9\u51e0\u4e2a\u4f2a\u5143\u7d20\u548cCSS\u5c5e\u6027\u90fd\u9700\u8981Chrome 135+\u652f\u6301\uff0c\u662f\u6bd4\u8f83\u65b0\u7684\u4e00\u4e2a\u7279\u6027\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202506\/2025-06-13_154656.png\" width=\"629\" height=\"320\" alt=\"scroll-marker scroll-button\u517c\u5bb9\u6027\" class=\"alignnone size-medium\" \/><\/p>\n<h4>::column\u4f2a\u5143\u7d20<\/h4>\n<p><code>::column<\/code>\u4f2a\u5143\u7d20\u4e5f\u662f\u540c\u4e00\u65f6\u95f4\u652f\u6301\u7684\u4f2a\u5143\u7d20\uff0c\u4e5f\u662f\u7528\u5728CSS carousel \u6548\u679c\u4e2d\u7684\uff0c\u548c\u4e0a\u9762\u7684\u533a\u522b\u5728\u4e8e\uff0c\u6c34\u5e73\u5e03\u5c40\u662f\u4f7f\u7528columns\u5e03\u5c40\u5b9e\u73b0\u3002<\/p>\n<p>\u6b64\u65f6\uff0c\u82e5\u8fd8\u662f\u6309\u7167\u672c\u6587\u7684\u6848\u4f8b\u4f7f\u7528\uff0c\u5219\u9700\u8981\u8fd9\u4e48\u4f7f\u7528\uff1a<\/p>\n<pre>zxx-slide::column {\r\n  scroll-snap-align: center;\r\n}\r\nzxx-slide::column::scroll-marker {\r\n  content: \"\";\r\n  \/* \u6309\u94ae\u6837\u5f0f... *\/\r\n}\r\nzxx-slide::column::scroll-marker:target-current {\r\n  background-color: #cd0000;\r\n}<\/pre>\n<p>\u5177\u4f53\u4e0d\u5c55\u5f00\uff0c\u56e0\u4e3acolumns\u5e03\u5c40\u7528\u7684\u4eba\u672c\u5c31\u5c11\uff0c\u522b\u8bf4\u8fd9\u4e2a\u4f2a\u5143\u7d20\u7684\u3002<\/p>\n<p>\u4f7f\u7528<code>::column<\/code>\u7684\u76ee\u7684\u662f\u4e0d\u5f71\u54cd\u539f\u672c\u7684columns\u5e03\u5c40\u3002<\/p>\n<p>\u6700\u540e\uff0c\u672c\u6587<code>::scroll-button<\/code>\u3001<code>::scroll-marker<\/code>\u4f2a\u5143\u7d20\u751f\u6210\u7684\u4ea4\u4e92\u6309\u94ae\uff0c\u5929\u7136\u652f\u6301\u65e0\u969c\u788d\u8bbf\u95ee\uff0c\u5f88\u68d2\uff01<\/p>\n<p>\u597d\u5427\uff0c\u5c31\u8bf4\u8fd9\u4e48\u591a\uff0c\u53c8\u662f\u5b66\u4e60\u7684\u4e00\u5929\uff01<\/p>\n<p>\ud83d\ude09\ud83d\ude0a\ud83d\ude07<br \/>\n\ud83e\udd70\ud83d\ude0d\ud83d\ude18<\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u4f1a\u7ecf\u5e38\u66f4\u65b0\u77e5\u8bc6\u70b9\u4ee5\u53ca\u4fee\u6b63\u4e00\u4e9b\u9519\u8bef\uff0c\u56e0\u6b64\u8f6c\u8f7d\u8bf7\u4fdd\u7559\u539f\u51fa\u5904\uff0c\u65b9\u4fbf\u6eaf\u6e90\uff0c\u907f\u514d\u9648\u65e7\u9519\u8bef\u77e5\u8bc6\u7684\u8bef\u5bfc\uff0c\u540c\u65f6\u6709\u66f4\u597d\u7684\u9605\u8bfb\u4f53\u9a8c\u3002<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=11727\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=11727<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202506\/2025-6-13_161945.jpeg\" width=\"160\" height=\"103\" alt=\"scroll snap \u6309\u94ae\u81ea\u5b9a\u4e49\u5c01\u9762\u56fe\" class=\"alignright size-medium\" loading=\"lazy\" \/><\/p>\n<p>CSS\u8d8a\u6765\u8d8a\u5f3a\u4e86\uff0cScroll Snap\u4ea4\u4e92\u53c8\u65b0\u589e\u4e86\u6309\u94ae\u548c\u5207\u6362\u6309\u94ae\u7684\u751f\u6210\u4e0e\u81ea\u5b9a\u4e49\uff0c\u7c7b\u4f3cCarousel \uff0cSlider\u8fd9\u7c7b\u7ecf\u5178\u4ea4\u4e92\u7eafCSS\u5c31\u80fd\u5b8c\u5168\u9a7e\u9a6d\u4e86\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[2062,2059,2061,2060,1101,1535,1327,1379,1814],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/11727"}],"collection":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=11727"}],"version-history":[{"count":7,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/11727\/revisions"}],"predecessor-version":[{"id":11752,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/11727\/revisions\/11752"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=11727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=11727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=11727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}