方法:1、使用“-webkit-scrollbar”属性设置,语法“-webkit-scrollbar{display:none;}”;2、在父元素div里设置“overflow: hidden”样式,并为父元素和子元素设置宽度。
本教程操作环境:windows7系统、HTML5&&CSS3版、Dell G3电脑。
方法一、 利用 css 3 的新特性 -webkit-scrollbar, 但是这种方式不兼容 火狐 和 IE
<!DOCTYPE html> <html> <head> <Meta charset=UTF-8> <title>超出部分隐藏滚动条</title> </head> <style type=text/css> #Box { width: 500px; height: 300px; overflow-x: hidden; overflow-y: scroll; line-height: 30px; text-align: center; } #Box::-webkit-scrollbar { display: none; } </style> <body> <!-- 兼容所有浏览器的超出部分滚动不显示滚动条 --> <div id=Box> 你好 </br>你好 </br> 你好 </br>你好 </br> 你好 </br>你好 </br> 你好 </br>你好 </br> 你好 </br>你好 </br> 你好 </br>你好 </br> 你好 </br>你好 </br> </div> </body> </html>
方法二、利用内外层嵌套, 模拟, 兼容所有浏览器, 相对于方法一比较麻烦, 使用时不能对滚动条声明任何样式
<!DOCTYPE html> <html> <head> <Meta charset=UTF-8> <title>超出部分滚动条</title> </head> <style type=text/css> #Box { /* 父容器设置宽度, 并超出部分不显示 */ width: 500px; height: 300px; overflow: hidden; } #Box > div { /* 子容器比父容器的宽度多 17 px, 经测正好是滚动条的默认宽度 */ width: 517px; height: 300px; line-height: 30px; text-align: center; overflow-y: scroll; } </style> <body> <!-- 兼容所有浏览器的超出部分滚动不显示滚动条 --> <div id=Box> <div> 你好 </br>你好 </br> 你好 </br>你好 </br> 你好 </br>你好 </br> 你好 </br>你好 </br> 你好 </br>你好 </br> 你好 </br>你好 </br> 你好 </br>你好 </br> </div> </div> </body> </html>
推荐学习:css视频教程
原文地址:https://www.jb51.cc/css/1206104.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。