import { ApiTable } from "@/components/api-table.tsx"; import { CustomizingYourSpacingScale, ResponsiveDesign, UsingACustomValue } from "@/components/content.tsx"; import { Example } from "@/components/example.tsx"; import { Figure } from "@/components/figure.tsx"; import { Stripes } from "@/components/stripes.tsx";
export const title = "scroll-padding"; export const description = "Utilities for controlling an element's scroll offset within a snap container.";
<ApiTable
rows={[
["scroll-p", "scroll-padding"],
["scroll-px", "scroll-padding-inline"],
["scroll-py", "scroll-padding-block"],
["scroll-ps", "scroll-padding-inline-start"],
["scroll-pe", "scroll-padding-inline-end"],
["scroll-pt", "scroll-padding-top"],
["scroll-pr", "scroll-padding-right"],
["scroll-pb", "scroll-padding-bottom"],
["scroll-pl", "scroll-padding-left"],
].flatMap(([prefix, property]) => [
[${prefix}-<number>
, ${property}: calc(var(--spacing) * <number>);
],
[-${prefix}-<number>
, ${property}: calc(var(--spacing) * -<number>);
],
[${prefix}-(<custom-property>)
, ${property}: var(<custom-property>);
],
[${prefix}-[<value>]
, ${property}: <value>;
],
])}
/>
Use the scroll-pt-<number>
, scroll-pr-<number>
, scroll-pb-<number>
, and scroll-pl-<number>
utilities like scroll-pl-4
and scroll-pt-6
to set the scroll offset of an element within a snap container:
<!-- [!code classes:scroll-pl-6] -->
<div class="snap-x scroll-pl-6 ...">
<div class="snap-start ...">
<img src="/img/vacation-01.jpg" />
</div>
<div class="snap-start ...">
<img src="/img/vacation-02.jpg" />
</div>
<div class="snap-start ...">
<img src="/img/vacation-03.jpg" />
</div>
<div class="snap-start ...">
<img src="/img/vacation-04.jpg" />
</div>
<div class="snap-start ...">
<img src="/img/vacation-05.jpg" />
</div>
</div>
Use the scroll-ps-<number>
and scroll-pe-<number>
utilities to set the scroll-padding-inline-start
and scroll-padding-inline-end
logical properties, which map to either the left or right side based on the text direction:
Left-to-right
Right-to-left
}<!-- [!code word:dir="ltr"] -->
<!-- [!code word:dir="rtl"] -->
<!-- [!code classes:scroll-ps-6] -->
<div dir="ltr">
<div class="snap-x scroll-ps-6 ...">
<!-- ... -->
</div>
</div>
<div dir="rtl">
<div class="snap-x scroll-ps-6 ...">
<!-- ... -->
</div>
</div>
To use a negative scroll padding value, prefix the class name with a dash to convert it to a negative value:
<!-- [!code classes:-scroll-ps-6] -->
<div class="-scroll-ps-6 snap-x ...">
<!-- ... -->
</div>
<UsingACustomValue utilities={["scroll-pl", "scroll-pe"]} value="24rem" name="scroll padding" variable="scroll-padding" />
<CustomizingYourSpacingScale utilities={[ "scroll-p", "scroll-px", "scroll-py", "scroll-ps", "scroll-pe", "scroll-pt", "scroll-pr", "scroll-pb", "scroll-pl", ]} />