css实现盒子横向滑动 重要

html-css06

css实现盒子横向滑动 重要,第1张

效果图:

css

.box {

background: #eee

padding: 10px 0

white-space: nowrap

/*文本不会换行,文本会在在同一行上继续*/

overflow-y: auto

/*可滑动*/

}

/*自定义滚动条的伪对象选择器, CSS 可以隐藏滚动条*/

.box::-webkit-scrollbar {

display: none

}

.box1 {

width: 49%

margin-left: 3%

height: 100px

background: #fff

display: inline-block

/*行内块元素*/

}

html:

<div class="box">

<div class="box1"></div>

<div class="box1"></div>

<div class="box1"></div>

<div class="box1"></div>

<div class="box1"></div>

</div>

纵向使用鼠标滚轮控制:可以设置页面的长度大于显示屏分辨率(可以设置body的height参数为3000px),多余的部分就以鼠标滚轮查看。

横向滚动条控制:在内容div或者article中设置横向长度大于屏幕分辨率,或者在父盒子设置overflow:scroll,多出的部分就使用滚动条显示。

从网页的美观性和用户体验角度,最好设置页面单向(纵向滚动)。横向滚动用户体验效果不是很好。