Hiding the scroll bar on an HTML page

前端 未结 21 1441
旧巷少年郎
旧巷少年郎 2020-11-22 00:07

Can CSS be used to hide the scroll bar? How would you do this?

21条回答
  •  眼角桃花
    2020-11-22 01:09

    I wrote a WebKit version with some options like auto hide, little version, scroll only-y, or only-x:

    ._scrollable{
        @size: 15px;
        @little_version_ratio: 2;
        @scrollbar-bg-color: rgba(0,0,0,0.15);
        @scrollbar-handler-color: rgba(0,0,0,0.15);
        @scrollbar-handler-color-hover: rgba(0,0,0,0.3);
        @scrollbar-coner-color: rgba(0,0,0,0);
    
        overflow-y: scroll;
        overflow-x: scroll;
        -webkit-overflow-scrolling: touch;
        width: 100%;
        height: 100%;
    
        &::-webkit-scrollbar {
            background: none;
            width: @size;
            height: @size;
        }
    
        &::-webkit-scrollbar-track {
            background-color:@scrollbar-bg-color;
            border-radius: @size;
        }
    
        &::-webkit-scrollbar-thumb {
            border-radius: @size;
            background-color:@scrollbar-handler-color;
            &:hover{
                background-color:@scrollbar-handler-color-hover;
            }
        }
    
        &::-webkit-scrollbar-corner {
          background-color: @scrollbar-coner-color;
        }
    
        &.little{
            &::-webkit-scrollbar {
                background: none;
                width: @size / @little_version_ratio;
                height: @size / @little_version_ratio;
            }
            &::-webkit-scrollbar-track {
                border-radius: @size / @little_version_ratio;
            }
            &::-webkit-scrollbar-thumb {
                border-radius: @size / @little_version_ratio;
            }
        }
    
        &.autoHideScrollbar{
            overflow-x: hidden;
            overflow-y: hidden;
            &:hover{
                overflow-y: scroll;
                overflow-x: scroll;
                -webkit-overflow-scrolling: touch;
                &.only-y{
                    overflow-y: scroll !important;
                    overflow-x: hidden !important;
                }
    
                &.only-x{
                    overflow-x: scroll !important;
                    overflow-y: hidden !important;
                }
            }
        }
    
        &.only-y:not(.autoHideScrollbar){
            overflow-y: scroll !important;
            overflow-x: hidden !important;
        }
    
        &.only-x:not(.autoHideScrollbar){
            overflow-x: scroll !important;
            overflow-y: hidden !important;
        }
    }
    

    http://codepen.io/hicTech/pen/KmKrjb

提交回复
热议问题