src/docs/background-attachment.mdx
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 = "background-attachment"; export const description = "Utilities for controlling how a background image behaves when scrolling.";
<ApiTable rows={[ ["bg-fixed", "background-attachment: fixed;"], ["bg-local", "background-attachment: local;"], ["bg-scroll", "background-attachment: scroll;"], ]} />
Use the bg-fixed utility to fix the background image relative to the viewport:
<!-- [!code classes:bg-fixed] -->
<div class="bg-[url(/img/mountains.jpg)] bg-fixed ...">
<!-- ... -->
</div>
Use the bg-local utility to scroll the background image with the container and the viewport:
<!-- [!code classes:bg-local] -->
<div class="bg-[url(/img/mountains.jpg)] bg-local ...">
<!-- ... -->
</div>
Use the bg-scroll utility to scroll the background image with the viewport, but not with the container:
<!-- [!code classes:bg-scroll] -->
<div class="bg-[url(/img/mountains.jpg)] bg-scroll ...">
<!-- ... -->
</div>