issue with CSS media queries(scrollbar)

前端 未结 7 1521
别那么骄傲
别那么骄傲 2020-11-27 06:28

I am having problem with css media query in Firefox. It works correct in Chrome like I made two DIVs and want a scrollbar. If I decrease the screen size of firefox upto 800p

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 06:55

    Firefox & Opera follows W3C spec which is to include scrollbar width in media queries width (the reason might be to avoid infinite loop as described in a comment here), while Webkit does not (possibly coz they think it makes no sense)

    There is a workaround (I've only tested this on FF), apparently if you force scrollbar to be visible all the time, then the width will now be consistent with Webkit. Here's the code:

    html
    {
       overflow:hidden;
       height:100%;
    }
    body
    {
       position:relative;
       overflow-y:scroll;
       height:100%;
       -webkit-overflow-scrolling:touch; /* So iOS Safari gets the inertia & rubber-band effect */
    }
    

    If you want to apply this to FF & Opera only, you can resort to CSS hacks:

    /* Firefox */
    @-moz-document url-prefix()
    {
        html
        {
            overflow:hidden;
            height:100%;
        }
        body
        {
            position:relative;
            overflow-y:scroll;
            height:100%;
            /*-webkit-overflow-scrolling:touch;*/
        }
    }
    
    /* Opera */
    x:-o-prefocus, html
    {
        overflow:hidden;
        height:100%;
    }
    x:-o-prefocus, body
    {
        position:relative;
        overflow-y:scroll;
        height:100%;
    }
    

    It goes without saying, the caveat is the scrollbar will be visible at all times, which might be an okay compromise.

提交回复
热议问题