简体   繁体   English

CSS / Javascript使div内的滚动条

[英]CSS/Javascript make scrollbar inside div

I have this custom scrollbar on my final project that i'm doing in school and the divs have a border radius of 15px, and when I put the custom scrollbar with the border radius of 15px, the scrollbar goes over the div which doesn't make it look as nice as I want it 我在我的最后一个项目中有这个自定义滚动条,我正在学校做,而div的边界半径为15px,当我把自定义滚动条的边界半径设置为15px时,滚动条会越过div而不是让它看起来像我想要的那样好

在此输入图像描述

How Can I put it inside the div so that edge won't show? 如何将它放在div中以便边缘不显示?

A little code of the CSS: 一小段CSS代码:

    #ruv_results, #stod2_results,#stod2bio_results, #stod3_results{
    text-align:center;


    }

.ruv_title_css, .stod2_title_css,.stod2bio_title_css, .stod3_title_css{
    font-size:20px;
    color:#ffffff;
    border:1px solid #000000;
    border-radius:15px;
    margin-top:25px;
    width:450px;
    height:550px;
    display:inline-block;
    vertical-align:top;
    box-shadow: 0 0 20px #000;
    background:#5e5e5e;
    box-shadow: inset 0 0 20px #000000;
    padding-right:4px;
    padding-left:4px;
    margin-bottom:10px;
    margin-right:6px;
    margin-left:6px;

}


::-webkit-scrollbar {
    width: 12px;
}

::-webkit-scrollbar-track {
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); 
    border-radius: 15px;
    height:90%;
}

::-webkit-scrollbar-thumb {
    border-radius: 15px;
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5); 
}

Without any code the best I could offer would be experimenting with z-indexes between the two elements. 没有任何代码,我能提供的最好的就是在两个元素之间试验z-index。 Perhaps the element with the scrollbar could sit under the containing element and hide the piece that sticks out. 也许带有滚动条的元素可以位于包含元素下面并隐藏突出的部分。

Also, don't forget to put the position property on the element with z-index. 另外,不要忘记将position属性放在具有z-index的元素上。

https://developer.mozilla.org/en-US/docs/Web/CSS/z-index?v=example https://developer.mozilla.org/en-US/docs/Web/CSS/z-index?v=example

One way would be to wrap the element in another div that has some padding: 一种方法是将元素包装在另一个具有一些填充的div中:

 .outer { background-color: #eee; box-shadow: inset 0 0 10px #ddd; border-radius: 15px; padding: 1em; } .inner { max-height: 200px; overflow: scroll; } /* Custom Scrollbar */ ::-webkit-scrollbar { width: 12px; } ::-webkit-scrollbar-track { -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); border-radius: 15px; height:90%; } ::-webkit-scrollbar-thumb { border-radius: 15px; -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5); } body { overflow: hidden; } 
 <div class="outer"> <div class="inner"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam a iaculis enim. Fusce pellentesque mauris vitae urna sodales gravida. Pellentesque pharetra est sit amet sodales faucibus. Mauris ultrices scelerisque feugiat. Duis magna arcu, condimentum at nunc ac, aliquet congue mauris. Curabitur feugiat urna rutrum urna porttitor, facilisis lacinia nisl facilisis. Nulla porttitor, neque id varius tincidunt, nibh lectus ornare mauris, eget consectetur elit lectus quis magna. Sed fringilla semper est eu imperdiet. Phasellus accumsan orci vitae quam hendrerit venenatis. Sed rhoncus nulla non enim euismod, a pretium nisi feugiat. In blandit augue gravida, viverra quam vitae, malesuada sem. In mollis ante non felis accumsan ullamcorper. Cras egestas, mi ut varius elementum, libero libero ultricies nulla, vel suscipit nisi dolor vel massa. Sed non nunc nibh. Vivamus eu libero gravida, interdum justo eu, facilisis ipsum. Pellentesque accumsan justo nec odio vestibulum iaculis. Maecenas ac turpis nisi. Nullam pharetra eros at tellus convallis, sed ornare orci egestas. </div> </div> 

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

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