如果您有兴趣,在我的网络应用程序中,我会在 <ul> 周围加上一个导航标签,使用 CSS 类作为水平滚动条。
<nav class="HORIZONTAL_SCROLL_NAV">
小提琴演示:https://jsfiddle.net/JonathanParentLevesque/z4gL1wkb/5/
最少的 CSS 是:
.HORIZONTAL_SCROLL_NAV {
-webkit-overflow-scrolling: touch;
overflow-x: auto;
overflow-y: hidden;
}
.HORIZONTAL_SCROLL_NAV>ul {
margin: 0 auto;
}
如果您想为滚动条设置样式,还可以添加一些额外的 CSS(这些浏览器支持:https://caniuse.com/#feat=css-scrollbar):
.HORIZONTAL_SCROLL_NAV::-webkit-scrollbar {
height: 10px;
}
.HORIZONTAL_SCROLL_NAV::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0);
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0);
-webkit-border-radius: 10px;
border-radius: 10px;
}
.HORIZONTAL_SCROLL_NAV::-webkit-scrollbar-thumb {
-webkit-border-radius: 10px;
border-radius: 10px;
background: rgba(255, 0, 0, 0.8);
-webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.5);
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.5);
}