Hide scroll bar, but while still being able to scroll

前端 未结 30 3323
悲哀的现实
悲哀的现实 2020-11-21 04:22

I want to be able to scroll through the whole page, but without the scrollbar being shown.

In Google Chrome it\'s:

::-webkit-scrollbar {
    display:         


        
30条回答
  •  萌比男神i
    2020-11-21 04:39

    Adding padding to an inner div, as in the currently accepted answer, won't work if for some reason you want to use box-model: border-box.

    What does work in both cases is increasing the width of the inner div to 100% plus the scrollbar's width (assuming overflow: hidden on the outer div).

    For example, in CSS:

    .container2 {
        width: calc(100% + 19px);
    }
    

    In JavaScript, cross-browser:

    var child = document.getElementById('container2');
    var addWidth = child.offsetWidth - child.clientWidth + "px";
    child.style.width = 'calc(100% + ' + addWidth + ')';
    

提交回复
热议问题