css 横向滑动设计思路
前端开发中,为了节省页面空间,有时需要在一行显示多元素,然后通过左右滑动来进行查看。特别是在页面空间极为珍贵的手机端,这种设计会被频繁用到。
效果如下:

实现方法:
html元素
<div class="container-wrap"> <div class="container"> <div class="box-1">hello</div> <div class="box-2">hello2</div> <div class="box-3">hello3</div> </div> </div>
CSS样式
.container-wrap {
width: 100%;
height: 50px;
background-color: rgba(0,0,0,0.8);
white-space: nowrap;
overflow: hidden;
overflow-x: scroll; /* 1 */
-webkit-backface-visibility: hidden;
-webkit-perspective: 1000;
-webkit-overflow-scrolling: touch; /* 2 */
text-align: justify; /* 3 */
&::-webkit-scrollbar {
display: none;
}
}
.container {
}
.container > div {
display: inline-block;
height: 50px;
color: #fff;
text-align: center;
line-height: 50px;
}
.box-1 {
width: 80%;
}
.box-2 {
width: 20%;
}
.box-3 {
width: 20%;
}


