> 웹 프론트엔드 > HTML 튜토리얼 > 横向滑动/滚动隐藏滚动条

横向滑动/滚动隐藏滚动条

WBOY
풀어 주다: 2016-06-01 14:33:00
원래의
1900명이 탐색했습니다.

上周,因为要用到可以横向滚动,不能出现滚动条的样式,网上搜了一圈也没有点想要的效果,干脆去偷一个~

先预览下效果吧

Vs

ok,上代码~

HTML:

<span style="color: #0000ff;"><span style="color: #800000;">div </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="demo-tab"</span><span style="color: #0000ff;">></span>
  <span style="color: #0000ff;"><span style="color: #800000;">ul </span><span style="color: #ff0000;">id</span><span style="color: #0000ff;">="items"</span><span style="color: #0000ff;">></span>
    <span style="color: #0000ff;"><span style="color: #800000;">li </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="item"</span><span style="color: #0000ff;">><span style="color: #800000;">div </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="item-on"</span><span style="color: #0000ff;">></span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span><span style="color: #800000;">li</span><span style="color: #0000ff;">></span>
    <span style="color: #0000ff;"><span style="color: #800000;">li </span><span style="color: #ff0000;">calss</span><span style="color: #0000ff;">="item"</span><span style="color: #0000ff;">><span style="color: #800000;">div</span><span style="color: #0000ff;">></span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span><span style="color: #800000;">li</span><span style="color: #0000ff;">></span>
    <span style="color: #0000ff;"><span style="color: #800000;">li </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="item"</span><span style="color: #0000ff;">><span style="color: #800000;">div</span><span style="color: #0000ff;">></span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span><span style="color: #800000;">li</span><span style="color: #0000ff;">></span>
    <span style="color: #0000ff;"><span style="color: #800000;">li </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="item"</span><span style="color: #0000ff;">><span style="color: #800000;">div</span><span style="color: #0000ff;">></span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span><span style="color: #800000;">li</span><span style="color: #0000ff;">></span>
  <span style="color: #0000ff;"></span><span style="color: #800000;">ul</span><span style="color: #0000ff;">></span>
<span style="color: #0000ff;"></span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span></span></span></span></span></span></span></span></span></span></span>
로그인 후 복사

CSS:

<span style="color: #800000;">.demo-tab</span>{<span style="color: #ff0000;">
  position</span>:<span style="color: #0000ff;">fixed</span>;<span style="color: #ff0000;">
  bottom</span>:<span style="color: #0000ff;">41px</span>;<span style="color: #ff0000;">
  overflow</span>:<span style="color: #0000ff;">hidden</span>;<span style="color: #008000;">/*</span><span style="color: #008000;">主要</span><span style="color: #008000;">*/</span><span style="color: #ff0000;">
  width</span>:<span style="color: #0000ff;">100%</span>;<span style="color: #ff0000;">
  height</span>:<span style="color: #0000ff;">50px</span>;<span style="color: #008000;">/*</span><span style="color: #008000;">主要</span><span style="color: #008000;">*/</span>
}<span style="color: #800000;">
.demo-tab ul</span>{<span style="color: #ff0000;">
  width</span>:<span style="color: #0000ff;">100%</span>;<span style="color: #ff0000;">
  height</span>:<span style="color: #0000ff;">60px</span>;<span style="color: #008000;">/*</span><span style="color: #008000;">主要</span><span style="color: #008000;">*/</span><span style="color: #ff0000;">
  font-size</span>:<span style="color: #0000ff;">0</span>;<span style="color: #ff0000;">
  background</span>:<span style="color: #0000ff;">#e8e8e8</span>;<span style="color: #ff0000;">
  overflow-x</span>:<span style="color: #0000ff;">scroll</span>;<span style="color: #008000;">/*</span><span style="color: #008000;">主要</span><span style="color: #008000;">*/</span><span style="color: #ff0000;">
  overflow-y</span>:<span style="color: #0000ff;">hidden</span>;<span style="color: #008000;">/*</span><span style="color: #008000;">主要</span><span style="color: #008000;">*/</span><span style="color: #ff0000;">
  white-space</span>:<span style="color: #0000ff;">nowrap</span>;
}<span style="color: #800000;">
.item</span>{<span style="color: #ff0000;">
  display</span>:<span style="color: #0000ff;">inline-block</span>;<span style="color: #ff0000;">
  width</span>:<span style="color: #0000ff;">33.3333333%</span>;<span style="color: #ff0000;">
  height</span>:<span style="color: #0000ff;">100%</span>;<span style="color: #ff0000;">
  padding</span>:<span style="color: #0000ff;">10px 0</span>;<span style="color: #ff0000;">
  font-size</span>:<span style="color: #0000ff;">18px</span>;<span style="color: #ff0000;">
  background</span>:<span style="color: #0000ff;">#9c9c9c</span>;
}<span style="color: #800000;">
.item-on</span>{<span style="color: #ff0000;">
  height</span>:<span style="color: #0000ff;">12px</span>;<span style="color: #ff0000;">
  background</span>:<span style="color: #0000ff;">#04be02</span>;
}
로그인 후 복사

总结一下,其实就是外层的div的高度要比里层ul/div或者其它元素的高度,然后overflow:hidden

这是目前已知的一种,也许还会有其它方法吧,希望这个方法能对dev有帮助。

美图,请欣赏,缩小尺寸了~


원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿