I am trying to position a number of buttons on a horizontally scrollable div at the bottom of a screen on a mobile device.
All buttons are of the same width.
Since I have more buttons than I can fit I’d like the div to scroll so that a button is never half on screen and half off.
In other words, the div should scroll only by fixed amounts and be "sticky" at those points.
Is that possible? I don’t even know what that could be called, otherwise I’d have googled a bit longer
2
Answers
you can put all buttons in the same container
and apply these changes
If this is not the case
please consider put more information
the relevant css is :
mdn : scroll-snap-type
scroll-snap-type needs to be applied to the container element
mdn : scroll-snap-align
scroll-snap-align on the child elements
here is a jsbin demonstrating the same thing in a larger viewport
the scrollbar is a bit ugly and can possibly be removed, i’d have to investigate it further
beware positioning things at the bottom of mobile devices can be tricky
if you need further assistance you can also ask in the
stackoverflow javascript chat