当我们的内容超出了我们的div,往往会出现滚动条,影响美观。尤其是当我们在做一些导航菜单的时候。滚动条一出现就破坏了UI效果。  我们不希望出现滚动条,也不希望超出去的内容被放逐,就要保留鼠标滚动的效果。

  这里介绍一个简单的方法:大体思路是在div外面再套一个div。这个div设置overflow:hidden,而内容div设置 overflow-y: scroll;overflow-x: hidden;

  然后再设置外层div的width小于内层div的width。

  这个内层div其实是会出现滚动条的,所以不影响鼠标的滚动效果,而且我们看不到滚动条了。

//css代码
.nav_wrap{
height: 400px;
width: 200px;
overflow: hidden;
border: 1px solid #ccc;
margin: 20px auto;
}
.nav_ul{
height: %;
width: 220px;
overflow-y: auto;
overflow-x: hidden;
} //html代码
<div class= "nav_wrap">
<ul class= "nav_ul">
<li class="nav_li">我是菜单1</li>
<li class="nav_li">我是菜单2</li>
</ul>
</div>

  这样的好处是兼容所有浏览器。

  下面介绍对各种浏览器进行的scroll-bar设置,这种就是兼容性不大好,对火狐不起作用

/*webkit内核*/
.scroll_content::-webkit-scrollbar {
width:0px;
height:0px;
}
.scroll_content::-webkit-scrollbar-button {
background-color:rgba(,,,);
}
.scroll_content::-webkit-scrollbar-track {
background-color:rgba(,,,);
}
.scroll_content::-webkit-scrollbar-track-piece {
background-color:rgba(,,,);
}
.scroll_content::-webkit-scrollbar-thumb{
background-color:rgba(,,,);
}
.scroll_content::-webkit-scrollbar-corner {
background-color:rgba(,,,);
}
.scroll_content::-webkit-scrollbar-resizer {
background-color:rgba(,,,);
}
/*o内核*/
.scroll_content .-o-scrollbar{
-moz-appearance: none !important;
background: rgba(,,,) !important;
}
.scroll_content::-o-scrollbar-button {
background-color:rgba(,,,);
}
.scroll_content::-o-scrollbar-track {
background-color:rgba(,,,);
}
.scroll_content::-o-scrollbar-track-piece {
background-color:rgba(,,,);
}
.scroll_content::-o-scrollbar-thumb{
background-color:rgba(,,,);
}
.scroll_content::-o-scrollbar-corner {
background-color:rgba(,,,);
}
.scroll_content::-o-scrollbar-resizer {
background-color:rgba(,,,);
}
/*IE10,IE11,IE12*/
.scroll_content{
-ms-scroll-chaining: chained;
-ms-overflow-style: none;
-ms-content-zooming: zoom;
-ms-scroll-rails: none;
-ms-content-zoom-limit-min: %;
-ms-content-zoom-limit-max: %;
-ms-scroll-snap-type: proximity;
-ms-scroll-snap-points-x: snapList(%, %, %, %, %);
-ms-overflow-style: none;
overflow: auto;
}

  所以还是选第一种吧,简单好用,哈哈

纯css解决div隐藏浏览器原生滚动条,但保留鼠标滚动效果的问题的更多相关文章

  1. 纯css,div隐藏滚动条,保留鼠标滚动效果。

    示例1: html,body { height: 100%; } body { overflow: hidden; } .full-screen { position: relative; width ...

  2. 纯CSS实现Div高度根据自适应宽度(百分百调整)

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  3. CSS字体渐变 & 隐藏浏览器滚动条 & grid布局(转载)

    字体渐变  https://www.zhangxinxu.com/study/201104/css3-text-gradient-2.html 隐藏浏览器滚动条  https://blog.csdn. ...

  4. html关于强制显示 隐藏浏览器的滚动条

    浏览器的滚动条在一些特殊的展示中,是不需要的,所以必须把它隐藏掉,文章主要介绍一些隐藏或者显示IE的水平或者垂直滚动条的实现代码,需要了解的朋友可以参考下: 相关css代码如下: //强制显示滚动条: ...

  5. 纯css实现div中未知尺寸图片的垂直居中

    1.淘宝的方法 在曾经的"淘宝UED招聘"中有这样一道题目: “使用纯CSS实现未知尺寸的图片(但高宽都小于200px)在200px的正方形容器中水平和垂直居中.” 当然出题并不是 ...

  6. 旁门左道通过JS与纯CSS实现显示隐藏层

    想必大家在开发前端页面时,肯定少不了显示隐藏层这一技术点.那么我简单粗暴地总结了以下两个小demo. 要实现该截图的功能:鼠标移动到我的好友这个选项卡时,灰色的隐藏层就会出现.

  7. CSS隐藏overflow默认滚动条同时保留滚动效果

    主要应用于移动端场景,仿移动端滚动效果.对于隐藏滚动条,众所周知overflow:hidden,但是想要的滚动效果也没了. 所以对于移动端webkit内核提供一个伪类选择器: .element::-w ...

  8. 一、纯css实现顶部进度条随滚动条滚动

    一.效果图 二.直接复制粘贴 <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...

  9. 分享11个纯css完成的图片浏览器

    图片画廊用于在网站上显示系列图片,它已成为网站重要的组成部分.实现图片画廊有很多种方法,今天要与大家分享的是11个使用纯 CSS 实现的图片画廊,它们代码少,效果炫,加载速度快,希望能对大家有所帮助. ...

随机推荐

  1. 【BZOJ-1913】signaling信号覆盖 极角排序 + 组合

    1913: [Apio2010]signaling 信号覆盖 Time Limit: 20 Sec  Memory Limit: 64 MBSubmit: 1232  Solved: 506[Subm ...

  2. 【学习笔记】python2和python3的input()

    python2中的input()只接受变量作为传入值,非变量内容会报错. >>> user=input("Enter your name:") Enter you ...

  3. Linux shell 脚本小记2

    .从文件读取 while read line do echo "line=$line" done < file.txt .将字符串转换为数组,并进行遍历 str=" ...

  4. Homebrew安装卸载

    安装homebrew ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/inst ...

  5. 你的产品适不适合做微信小程序?你需要这篇产品逻辑分析

      自2017年1月9日张小龙宣布万众瞩目的“微信小程序”正式上线了.以名字看,感觉像是突出了“将你的程序接入微信”的意思. 我们此前分析过微信的功能迭代节奏:一般微信重要的功能规划周期,大约会在在9 ...

  6. shu_1016 栈

    cid=1079&pid=2">http://202.121.199.212/JudgeOnline/problem.php?cid=1079&pid=2 分析: Ca ...

  7. LPC1800 and LPC4300 Boot/ISP/CRP

    MCU的启动方式有很多种:UART接口,扩展的静态存储单元(NOR Flash), SPI Flash,quad SPI Flash,高速USB0和USB1.另外可以通过对OTP存储单元的编程. 首先 ...

  8. CoreSight™ Technology

    ARM Cortex-M processor-based devices use the ARM CoreSight technology which introduces powerful new  ...

  9. SWD Connect/Transfer Source Code

    Serial Wire Debug interface The Serial Wire Debug protocol operates with a synchronous serial interf ...

  10. go中的接口

    对于golang的接口,纠结两天了,今天有种茅塞顿开的感觉,有必要写点东西了. 纠结接口,说白了就是搞不透接口,方法,结构体几者之间的关系以及具体的用途.可以简单的从三者的定义说起,接口说白了就是一个 ...