Only Enable Scrollbar on Body And Disable on Other

2019-07-27 04:46发布

问题:

Is there a way to only enable scrollbar on the body only and disable on other divs?

This code disables all scrollbar in everywhere:

::-webkit-scrollbar {
    display:none;
}

How to enable only on the body?


EDITED

Changing overflow is not the one I want. Let's say I want to create mobile friendly view editor, which able to scroll up and down inside the div content but the scrollbar should be hidden. The scrollbar in the body is necessary because I will have to edit the view from my desktop web browser.

Changing overflow will not help in this case.

回答1:

These two CSS properties can be used to hide the scrollbars:

#parent{
    height: 100%;
    width: 100%;
    overflow: hidden;
}

#child{
    width: 100%;
    height: 100%;
    overflow-y: scroll;
}

jsfiddle: http://jsfiddle.net/5GCsJ/954/