Scrollable
Scrollable
adds overflow: auto
to an element and sets up CSS Scroll Snap for you.
-->
Scrollable
adds overflow: auto
to an element and sets up CSS Scroll Snap for you.
Just add Scrollable-horizontal
or Scrollable-vertical
to make an element scrollable with the enhancements we’ve built into Scrollable
.
Try scrolling the demo to see it work! Checkout the options in the guide to customize CSS Scroll Snap behaviour.
Few people know you can scroll through horizontal content with a mouse wheel. We fixed this by converting vertical scrolls to horizontal scrolls with pretty good finese.
It even reactivates CSS Scroll Snap after scrolling!
Just use the ScrollableHorizontal
script to activate this behaviour.
Mouse over this and use your scroll wheel!
Overflow cuts off outlines of elements which extend over their boundaries. We’ve added a small utility that helps to prevent this from happening.
Scrollable
does three things:
overflow:auto
property to the container.You can create a horizontal scrollable component with Scrollable-horizontal
. This uses Horizontal
under the hood.
You can create a vertical scrollable component with Scrollable-vertical
. For Vertical scrollbars, you would need a height
or max-height
declaration to determine the size of the container.
CSS Scroll Snap is enabled in Scrollable
(both horizontal and vertical) by default. To alter CSS Scroll Snap behaviour and positions, you need to change --snap-type
, --snap-align
or --scroll-margin
.
--snap-type
determines the strictness of the snap points if there is one.
Possible values are:
none
: Disables CSS Scroll Snapproximity
: Enforces snap points loosely. (Default value).mandatory
: Enforces snap points strictly--snap-align
determines where the snap point is. Possible values are: start
(default), center
, and end
.
--scroll-margin
determines the amount of space between the edge of the container and the snap point. The default value is 1rem
.
To disable CSS Scroll Snap, you can use Scrollable-noSnap
or set --snap-type
to none
The big problem for content with horizontal scrollbars is: most people don’t know they can scroll horizontally with the mouse.
Did you know you can scroll horizontally by pressing down the shift key? Most developers don’t know this, so don’t expect your users to know.
We’ve created a ScrollableHorizontal
script that combats this problem by converting vertical scrolls to horizontal scrolls with finese and taste. (As much as possible, at least)
Here’s what it does in a nutshell:
Scrollable
elementTo use the script, you need to import and run ScrollableHorizontal
from the layouts library.
Next, add the Scrollable-prefersHorizontalScroll
class to your Scrollable-horizontal
element.
ScrollableHorizontal
disables CSS Scroll Snap when scrolling in order for a scroll to work as you would expect. It enables CSS Scroll Snap again after scrolling.
You can adjust this delay between when a user scrolls and when CSS Scroll Snap is enabled again with --scrollSnapDelay
(in milliseconds).
ScrollableHorizontal
does not scan for elements that were created after the script has run.
If you add a Scrollable
layout afterward and you want to use Scrollable-preferHorizontalScroll
, make sure you run the ScrollableHorizontal
script again when the component is loaded.
The best way to style scrollbars is to use variables provided by our Scrollbar
component.
When Scrollable components have an overflow, the container behaves somewhat like overflow:hidden
where any outlines — which are used for focus states in Splendid Labz — will be cut off.
To prevent outlines from being cut off, you can use Scrollable-preserveOutlines
. This adds negative margins and positive paddings to expand the scrollable container — just enough to show the outlines.
Here’s an example for you to see this at work.
Tab onto these buttons and you’ll see the outlines are cut off
Tab onto these buttons and you’ll see the outlines are intact
If you use Scrollable-preserveOutlines
, you should not add margin or padding
to the Scrollable
element. Use margins or paddings elsewhere.
Splendid Labz is free because we love developers and we want to contribute back to the ecosystem.
We only charge for access to the documentation to keep the project going. If you don't wish to pay, feel free to use the content from the features tab, our blogs or our videos as your guide.
Scrollable
does three things:
overflow:auto
property to the container.You can create a horizontal scrollable component with Scrollable-horizontal
. This uses Horizontal
under the hood.
You can create a vertical scrollable component with Scrollable-vertical
. For Vertical scrollbars, you would need a height
or max-height
declaration to determine the size of the container.
CSS Scroll Snap is enabled in Scrollable
(both horizontal and vertical) by default. To alter CSS Scroll Snap behaviour and positions, you need to change --snap-type
, --snap-align
or --scroll-margin
.
--snap-type
determines the strictness of the snap points if there is one.
Possible values are:
none
: Disables CSS Scroll Snapproximity
: Enforces snap points loosely. (Default value).mandatory
: Enforces snap points strictly--snap-align
determines where the snap point is. Possible values are: start
(default), center
, and end
.
--scroll-margin
determines the amount of space between the edge of the container and the snap point. The default value is 1rem
.
To disable CSS Scroll Snap, you can use Scrollable-noSnap
or set --snap-type
to none
The big problem for content with horizontal scrollbars is: most people don’t know they can scroll horizontally with the mouse.
Did you know you can scroll horizontally by pressing down the shift key? Most developers don’t know this, so don’t expect your users to know.
We’ve created a ScrollableHorizontal
script that combats this problem by converting vertical scrolls to horizontal scrolls with finese and taste. (As much as possible, at least)
Here’s what it does in a nutshell:
Scrollable
elementTo use the script, you need to import and run ScrollableHorizontal
from the layouts library.
Next, add the Scrollable-prefersHorizontalScroll
class to your Scrollable-horizontal
element.
ScrollableHorizontal
disables CSS Scroll Snap when scrolling in order for a scroll to work as you would expect. It enables CSS Scroll Snap again after scrolling.
You can adjust this delay between when a user scrolls and when CSS Scroll Snap is enabled again with --scrollSnapDelay
(in milliseconds).
ScrollableHorizontal
does not scan for elements that were created after the script has run.
If you add a Scrollable
layout afterward and you want to use Scrollable-preferHorizontalScroll
, make sure you run the ScrollableHorizontal
script again when the component is loaded.
The best way to style scrollbars is to use variables provided by our Scrollbar
component.
When Scrollable components have an overflow, the container behaves somewhat like overflow:hidden
where any outlines — which are used for focus states in Splendid Labz — will be cut off.
To prevent outlines from being cut off, you can use Scrollable-preserveOutlines
. This adds negative margins and positive paddings to expand the scrollable container — just enough to show the outlines.
Here’s an example for you to see this at work.
Tab onto these buttons and you’ll see the outlines are cut off
Tab onto these buttons and you’ll see the outlines are intact
If you use Scrollable-preserveOutlines
, you should not add margin or padding
to the Scrollable
element. Use margins or paddings elsewhere.
Here’s the CSS for Scrollable
.
Splendid Labz is free because we love developers and we want to contribute back to the ecosystem.
We only charge for access to the documentation to keep the project going. If you don't wish to pay, feel free to use the content from the features tab, our blogs or our videos as your guide.
Here’s the CSS for Scrollable
.
Class | Description |
---|---|
Scrollable-horizontal | Creates a horizontal scrollable element |
Scrollable-vertical | Creates a vertical scrollable element |
Scrollable-prefersHorizontalScroll | Use ScrollableHorizontal script to change vertical mousewheel scrolls into horizontal scrolls with finese |
Scrollable-preserveOutlines | Ensures outlines are not cut off |
Scrollable-noSnap | Disables CSS Scroll Snap |
Variable | Default | Possible values | Description |
---|---|---|---|
--snap-type | proximity | none proximity mandatory | Value for scroll-snap-type . Determines strictness of the snap |
--snap-align | start | start center end | Value for css-snap-align . Determines location to snap to. |
--scroll-margin | 0 | Any length value | Amount of space between the edge of the container and the snap point |
Variable | Default | Description |
---|---|---|
--scrollSnapDelay | 1000 | Time (in ms ) to wait before activating CSS Scroll Snap after user scrolls. |
Splendid Labz is free because we love developers and we want to contribute back to the ecosystem.
We only charge for access to the documentation to keep the project going. If you don't wish to pay, feel free to use the content from the features tab, our blogs or our videos as your guide.
Class | Description |
---|---|
Scrollable-horizontal | Creates a horizontal scrollable element |
Scrollable-vertical | Creates a vertical scrollable element |
Scrollable-prefersHorizontalScroll | Use ScrollableHorizontal script to change vertical mousewheel scrolls into horizontal scrolls with finese |
Scrollable-preserveOutlines | Ensures outlines are not cut off |
Scrollable-noSnap | Disables CSS Scroll Snap |
Variable | Default | Possible values | Description |
---|---|---|---|
--snap-type | proximity | none proximity mandatory | Value for scroll-snap-type . Determines strictness of the snap |
--snap-align | start | start center end | Value for css-snap-align . Determines location to snap to. |
--scroll-margin | 0 | Any length value | Amount of space between the edge of the container and the snap point |
Variable | Default | Description |
---|---|---|
--scrollSnapDelay | 1000 | Time (in ms ) to wait before activating CSS Scroll Snap after user scrolls. |