I've noticed that a small laptop with a 1920x1080 screen, windows 10 will auto adjust the scaling. I've seen it as high as 150%. Is there a way we can detect this? My media queries don't kick in as they're set in px.
js: screenPPI = document. getElementById('ppitest'). offsetWidth; This got me 96, which corresponds to my system's ppi.
Alternatively, right click on an empty area on your desktop and select Display. In System, settings screen click on Displayoption from left side. Under Change the size of text, apps, and other items: 100% (Recommended), move the slider left or right to the DPI percentage you want to set for that display.
Try accessing window.devicePixelRatio variable. The Window property devicePixelRatio returns the ratio of the resolution in physical pixels to the resolution in CSS pixels for the current display device. This value could also be interpreted as the ratio of pixel sizes: the size of one CSS pixel to the size of one physical pixel.
CSS alone can’t really do this. But CSS is still the answer! transform: scale (); is what we need. It scales things perfectly proportionally. We just need to give it a number to scale it by, and that scale we can figure out with some JavaScript.
You might use the window.devicePixelRatio property to get the scaling ratio of the screen/page. This works well in current IE, Edge, Chrome and Firefox on the desktop (Windows), but it doesn't seem to be a current standard.
We just need to give it a number to scale it by, and that scale we can figure out with some JavaScript. The trick is: var scale = Math.min( availableWidth / contentWidth, availableHeight / contentHeight ); Here’s one possible approach to that, using jQuery and jQuery UI Resizeable (because that’s easy and comfortable for me):
Try accessing window.devicePixelRatio
variable.
The Window property devicePixelRatio returns the ratio of the resolution in physical pixels to the resolution in CSS pixels for the current display device. This value could also be interpreted as the ratio of pixel sizes: the size of one CSS pixel to the size of one physical pixel. In simpler terms, this tells the browser how many of the screen's actual pixels should be used to draw a single CSS pixel.
More info about it: https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio
You could also use CSS resolution
for this, more about this here: https://developer.mozilla.org/en-US/docs/Web/CSS/@media/resolution
@media (resolution: 150dpi) {
p {
color: red;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With