I'm working on a list with horizontal scroll functionality to allow users to view content by scrolling. I have successfully implemented this, but I'm facing a couple of challenges that I need help with:
- I want the first item in the list to always start centered horizontally, similar to how a text block would appear. I've tried different CSS techniques like flex-box, but they end up centering the entire scrollable content instead of just the first item. Even using Bootstrap's offset doesn't work well across different screen sizes.
Current Appearance: https://i.sstatic.net/7dj8F.jpg
Desired Appearance: https://i.sstatic.net/3pTTS.jpg
- Another issue I'm facing is that my horizontal scrollbar looks like Image 1. Is there a way to make the scrollbar appear in the center without taking up the entire width while still allowing users to scroll through the content?
https://i.sstatic.net/SpEU2.jpg
Any suggestions or guidance would be greatly appreciated! It seems like solving these issues might require JavaScript, which I'm not very skilled at. I'm even willing to pay for a solution at this point due to my urgency.
Thank you in advance!
You can view the codepen demo here: https://codepen.io/anon/pen/EqwZLJ
.scroll-horizontal ul {
position: relative;
margin: 0;
padding: 0;
list-style: none;
white-space: nowrap;
}
.scroll-horizontal ul li {
display: inline-block;
max-width: 735px;
margin-right: 15px;
overflow: hidden;
}
.scroll-horizontal {
padding-bottom: 50px;
margin-bottom: 150px;
}
.overflow-x {
position: relative;
overflow-x: scroll;
}
.overflow-x::-webkit-scrollbar {
-webkit-appearance: none;
}
.overflow-x::-webkit-scrollbar:vertical {
width: 11px;
}
.overflow-x::-webkit-scrollbar:horizontal {
height: 11px;
}
.overflow-x::-webkit-scrollbar-thumb {
border-radius: 8px;
border: 2px solid white; /* should match background, can't be transparent */
background-color: rgba(0, 0, 0, .5);
}