Aller au contenu

Overflow

import { ApiTable } from "@/components/api-table.tsx"; import { Example } from "@/components/example.tsx"; import { Figure } from "@/components/figure.tsx"; import { ResponsiveDesign } from "@/components/content.tsx";

export const title = "overflow"; export const description = "Utilities for controlling how an element handles content that is too large for the container.";

Examples

Showing content that overflows

Use the overflow-visible utility to prevent content within an element from being clipped:

{
Andrew Alfred Technical advisor
}
<!-- [!code classes:overflow-visible] -->
<div class="overflow-visible ...">
  <!-- ... -->
</div>

Note that any content that overflows the bounds of the element will then be visible.

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
}
<!-- [!code classes:overflow-hidden] -->
<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:

{
Andrew Alfred Technical advisor
Debra Houston Analyst
Jane White Director, Marketing
Ray Flint Technical Advisor
}
<!-- [!code classes:overflow-auto] -->
<div class="overflow-auto ...">
  <!-- ... -->
</div>

Unlike overflow-scroll, which always shows scrollbars, this utility will only show them if scrolling is necessary.

Scrolling horizontally if needed

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

{
Andrew
Emily
Whitney
David
Kristin
Sarah
}
<!-- [!code classes:overflow-x-auto] -->
<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
}
<!-- [!code classes:overflow-y-auto] -->
<div class="h-32 overflow-y-auto ...">
  <!-- ... -->
</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
}
<!-- [!code classes:overflow-x-scroll] -->
<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
}
<!-- [!code classes:overflow-y-scroll] -->
<div class="overflow-y-scroll ...">
  <!-- ... -->
</div>

Scrolling in all directions

Use the overflow-scroll utility to add scrollbars to an element:

{
{/* Calendar frame */}
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
{/* Calendar contents */}
5 AM Flight to Vancouver Toronto YYZ
6 AM Breakfast Mel's Diner
5 PM 🎉 Party party 🎉 We like to party!
}
<!-- [!code classes:overflow-scroll] -->
<div class="overflow-scroll ...">
  <!-- ... -->
</div>

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.

Responsive design