简体   繁体   English

带有圆角的 div 中的滚动条

[英]Scrollbar in a div with rounded corners

I have a <div> with rounded corners.我有一个带圆角的<div> I'm actually using it as the drop down list part of a drop down menu.我实际上将它用作下拉菜单的下拉列表部分。 Inevitably, every once in awhile it will contain lots of information so it would just have to have a scroll bar.不可避免地,每隔一段时间它就会包含大量信息,因此它只需要一个滚动条。 However, when the scroll bar gets displayed, it removes the rounded corners on that side which is highly undesirable.但是,当滚动条显示时,它会删除那一侧的圆角,这是非常不受欢迎的。 Here's the jsFiddle .这是jsFiddle

 #test { background: red; max-width: 200px; max-height: 200px; border-radius: 10px; overflow-y: scroll; }
 <div id="test"> Text <br /> Text <br /> Text <br /> Text <br /> Text <br /> Text <br /> Text <br /> Text <br /> Text <br /> Text <br /> Text <br /> Text <br /> Text <br /> Text <br /> Text <br /> </div>

I tried using custom solution like jQuery's mCustomScrollBar which I love but it does the exact same thing with the rounded corners.我尝试使用自定义解决方案,如我喜欢的 jQuery 的 mCustomScrollBar,但它对圆角的作用完全相同。 Any workarounds or tips on how to approach this problem?有关如何解决此问题的任何解决方法或提示?

You can use a jQuery plugin jScrollPane , and customize the color, width etc as needed.您可以使用 jQuery 插件jScrollPane ,并根据需要自定义颜色、宽度等。

See the following example of OS X style scrollbar.请参阅以下 OS X 样式滚动条示例。 And see here for dynamic width.在此处查看动态宽度。

jsFiddle js小提琴

 $(function() { $('.scroll-pretty').jScrollPane({ verticalGutter: 2 }); });
 .scroll-pretty { background: grey; border-radius: 5px; width: 300px; height: 150px; overflow: auto; outline: 0; } .scroll-pretty .jspVerticalBar { background: transparent; width: 10px; } .scroll-pretty .jspTrack { background: transparent; width: 8px; } .scroll-pretty .jspCap { background: transparent; display: block; height: 2px; /*same as verticalGutter value*/ } .scroll-pretty .jspDrag { background: silver; border-radius: 10px; } .scroll-pretty p { margin: 10px; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.13/jquery.mousewheel.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jScrollPane/2.0.23/script/jquery.jscrollpane.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jScrollPane/2.0.23/style/jquery.jscrollpane.min.css"> <div class="scroll-pretty"> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec in ligula id sem tristique ultrices eget id neque. Duis enim turpis, tempus at accumsan vitae, lobortis id sapien. Pellentesque nec orci mi, in pharetra ligula. Nulla facilisi. Nulla facilisi. Mauris convallis venenatis massa, quis consectetur felis ornare quis. Sed aliquet nunc ac ante molestie ultricies. Nam pulvinar ultricies bibendum. Vivamus diam leo, faucibus et vehicula eu, molestie sit amet dui. Proin nec orci et elit semper ultrices. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed quis urna mi, ac dignissim mauris. Quisque mollis ornare mauris, sed laoreet diam malesuada quis. Proin vel elementum ante. Donec hendrerit arcu ac odio tincidunt posuere. Vestibulum nec risus eu lacus semper viverra. </p> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM