Stop Firefox DPI Scaling (when Windows setting is at 125%)

喜欢而已 提交于 2019-11-28 06:17:39
Terry Robb

This frustrated me too, but luckily there is a solution.

Navigate to about:config. (Click accept on any warnings telling you to be careful with advanced features)

Search for layout.css.devPixelsPerPx and change its value to 1.0 and your issue should be fixed.

It was something implemented in Firefox 22.

You could easily let your website address users with settings at higher zoom levels by including a media query like:

@media only screen and( -webkit-min-device-pixel-ratio: 1.25 ),
       only screen and(      -o-min-device-pixel-ratio: 5/4 ),
       only screen and( min-resolution: 120dpi ),
       only screen and( min-resolution: 1.25dppx ) {
    body {
        font-size: 1rem;
    }
} 

See this article for an extended explanation and why the cleaned up solution of the media query is sufficient for a broad browser support: IE9+, Fx3.5+, Opera9.5+, Webkit Browsers Chrome and Safari, both Desktop and Mobile.

Your could try something like this below. There are some caveats using this, but for some situations it is worth using it.

    @media screen and (min-resolution: 120dpi) { 
    /*body {transform: scale(0.8);width: 125%;height: 125%;margin-left: -12.5%;}*/
    body {transform: scale(0.8);transform-origin:top left;width: 125%;height: 125%;}
}

Commented /*body....*/ example scale may be easier to understand yet worse, f.e. because scaling should be done based on transform-origin css rule top left edge. Then things can be rendered better especially in Chrome.

if you use width: 125%, your RWD css should react differently to changing browser sizes on account of this from what you expected when screen ratio was 100%. And you might reasonably accept this - this is RWD and the difference is 25%. But some people might want to adapt their css like this:

@media screen and (min-width: 1000px)

you also need to adjust:

@media screen and (min-width: 800px)

probably not 1250px but 800px like I did.

Edge, Chrome, FF do pretty good. IE 11 rendered the worst yet not hopelessly.

There are some problems in FF (not edge, chrome) when expanding select fields - solution css select. Some borders can can be visible some dissapear on FF (maybe not edge, chrome)

There can be some issues not mentioned here like when you use carousel like owlcarousel on your page.

Yet I think it is greater probability to save more time with this example tested still too little.

You have to use exact scaling like 0.8 for 125% screen for your images to be rendered as sharp as possible.

I noticed that when switching to different dpi resolutions using ctrl +/i in a desktop browser and for sure using multitouch gestures in mobile browsers, a browser changes dpi too, so any solution using @media min/max-resolution may not work as expected. What is needed in css is to read system resolution not a browser. However as i see this resolution change doesn't take place like then when someone changes browser size manually or by rotating a mobile device.

Thank you Tatsuyuki Ishi for correcting some errors of my answer.

Set it to 1.25: that keeps the user interface larger, but resets the website to 100% pixel mapping.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!