标签:box 滚轮 height 滚动条 width html overflow 隐藏 你好
原文:https://www.cnblogs.com/lovling/p/8000363.html
方法一, 利用 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>
另参考:https://www.cnblogs.com/xiaostudy/p/10821191.html
标签:box,滚轮,height,滚动条,width,html,overflow,隐藏,你好 来源: https://www.cnblogs.com/zhanglw456/p/11356632.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。