返回介绍

Overflow

发布于 2024-07-30 22:16:08 字数 20046 浏览 0 评论 0 收藏 0

Utilities for controlling how an element handles content that is too large for the container.

Quick reference

ClassProperties
overflow-autooverflow: auto;
overflow-hiddenoverflow: hidden;
overflow-clipoverflow: clip;
overflow-visibleoverflow: visible;
overflow-scrolloverflow: scroll;
overflow-x-autooverflow-x: auto;
overflow-y-autooverflow-y: auto;
overflow-x-hiddenoverflow-x: hidden;
overflow-y-hiddenoverflow-y: hidden;
overflow-x-clipoverflow-x: clip;
overflow-y-clipoverflow-y: clip;
overflow-x-visibleoverflow-x: visible;
overflow-y-visibleoverflow-y: visible;
overflow-x-scrolloverflow-x: scroll;
overflow-y-scrolloverflow-y: scroll;

Basic usage

Showing content that overflows

Use the overflow-visible utility to prevent content within an element from being clipped. Note that any content that overflows the bounds of the element will then be visible.

Andrew Alfred Technical advisor
<div class="overflow-visible ..."></div>

Hiding content that overflows

Use the overflow-hidden utility to clip any content within an element that overflows the bounds of that element.

Andrew Alfred Technical advisor
<div class="overflow-hidden ..."></div>

Scrolling if needed

Use the overflow-auto utility to add scrollbars to an element in the event that its content overflows the bounds of that element. Unlike overflow-scroll, which always shows scrollbars, this utility will only show them if scrolling is necessary.

Andrew Alfred Technical advisor Debra Houston Analyst Jane White Director, Marketing Ray Flint Technical Advisor
<div class="overflow-auto ..."></div>

Scrolling horizontally if needed

Use the overflow-x-auto utility to allow horizontal scrolling if needed.

Andrew Emily Whitney David Kristin Sarah
<div class="overflow-x-auto ..."></div>

Scrolling vertically if needed

Use the overflow-y-auto utility to allow vertical scrolling if needed.

Andrew Alfred Technical advisor Debra Houston Analyst Jane White Director, Marketing Ray Flint Technical Advisor
<div class="overflow-y-auto h-32 ..."></div>

Scrolling horizontally always

Use the overflow-x-scroll utility to allow horizontal scrolling and always show scrollbars unless always-visible scrollbars are disabled by the operating system.

Andrew Emily Whitney David Kristin Sarah
<div class="overflow-x-scroll ..."></div>

Scrolling vertically always

Use the overflow-y-scroll utility to allow vertical scrolling and always show scrollbars unless always-visible scrollbars are disabled by the operating system.

Andrew Alfred Technical advisor Debra Houston Analyst Jane White Director, Marketing Ray Flint Technical Advisor
<div class="overflow-y-scroll ..."></div>

Scrolling in all directions

Use the overflow-scroll utility to add scrollbars to an element. Unlike overflow-auto, which only shows scrollbars if they are necessary, this utility always shows them. Note that some operating systems (like macOS) hide unnecessary scrollbars regardless of this setting.

Sun Mon Tue Wed Thu Fri Sat 5 AM 6 AM 7 AM 8 AM 9 AM 10 AM 11 AM 12 PM 1 PM 2 PM 3 PM 4 PM 5 PM 6 PM 7 PM 8 PM 5 AM Flight to Vancouver Toronto YYZ 6 AM Breakfast Mel's Diner 5 PM ???? Party party ???? We like to party!
<div class="overflow-scroll ..."></div>

Applying conditionally

Hover, focus, and other states

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

<div class="overflow-auto hover:overflow-scroll">
  <!-- ... -->
</div>

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

Breakpoints and media queries

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

<div class="overflow-auto md:overflow-scroll">
  <!-- ... -->
</div>

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文