1. 交互
  2. 滚动行为

Quick reference

Class
Properties
scroll-autoscroll-behavior: auto;
scroll-smoothscroll-behavior: smooth;

基本用法

¥Basic usage

添加平滑滚动

¥Adding smooth scrolling

使用 scroll-smooth 工具可以在元素内实现平滑滚动。

¥Use the scroll-smooth utility to enable smooth scrolling within an element.

<html class="scroll-smooth">
  <!-- ... -->
</html>

有条件地应用

悬停、聚焦和其他状态

Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use focus:scroll-auto to only apply the scroll-auto utility on focus.

<html class="scroll-smooth focus:scroll-auto">
  <!-- ... -->
</html>

For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.

断点和媒体查询

You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:scroll-auto to apply the scroll-auto utility at only medium screen sizes and above.

<html class="scroll-smooth md:scroll-auto">
  <!-- ... -->
</html>

To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.