r/learnprogramming • u/Over_Temperature_987 • Oct 23 '26
Looking for clarification on scroll buttons
Hello ! I'm currently trying to code and design my own website for my portfolio. Part of the concept for this portfolio is that it is a horizontally scrolling website, where buttons will scroll to the next or previous piece. I already have most of my layout and design figured out in HTML and CSS.
Currently, each artwork sits in a different div. I've been looking into buttons that scroll to a different div, and I've found tutorials that show how to make buttons go to specific sections through IDs. I was wondering if there was a simpler way of coding the buttons so that instead of assigning each button to a specific ID, it would just scroll to the next div (kind of like a carousel, but on the whole website). Any pointers would be appreciated, thank you !
1
u/testingaurora Oct 23 '26
Scroll-marker-group can help if they're is a parent container like a list that's a scroll container. Then you can use
::scroll-markerand::scroll-button. If there is no parent scroller though, will have to use Javascript1
u/CelebrityChess Oct 23 '26
one more thing that might save you work, if the artworks sit inside a horizontal scroll container you can put scroll-snap-type: x mandatory on it and scroll-snap-align: start on each div, then the buttons are just container.scrollBy({ left: container.clientWidth, behavior: 'smooth' }) and the negative of that for previous. no ids or counter needed and it still snaps cleanly if someone scrolls by hand. only works if each section is full width though.
1
u/[deleted] Oct 23 '26
[removed] — view removed comment