Stop Firefox DPI Scaling (when Windows setting is

2020-02-02 15:41发布

问题:

I'm currently making a webpage and testing it in chrome works fine, but in Firefox - it is zoomed in.

This is because my DPI in Windows is set to 125%, and Firefox detects this, and adjusts every webpage accordingly.

However, my webpage is not meant to be viewed at such a zoom level, the images aren't made to be displayed that big, and hence it looked blurred/pixelated. The general layout of the page is messed up too, because everything is so big.

Now, this doesn't affect most people - as their DPI would be at 100% in Windows. However, I want it to be the same on all browsers.

I've searched and have found solutions as for the user to disable this "feature" - but I want to be able to disable it from my website - so it doesn't look wrong to the user in the first place.

e.g. one post says:

1) Type about:config in address bar
2) search for layout.css.devPixelsPerPx
3) change value of layout.css.devPixelsPerPx from -1.0 to 1.0

But that isn't what I'm looking for. Is there any way to disable this from CSS/HTML/anything?

Thanks.

回答1:

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.



回答2:

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.



回答3:

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.



回答4:

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