Firefox, Windows DPI scaling and CSS max-width media query - css

I have a website where a media query decides whether to show the right-hand column, depending on browser width. CSS looks like this:
#media only screen and (max-width: 1152px) {
#column_right {display:none}
}
Recently, I was testing this on a Windows box where the DPI scaling is set to 125%. The resolution of the monitor is set to 1024x768. So in theory, because there are only 1024 CSS pixels available, I assume this would match the media query.
However, this is not the behavior that occurs! It seems that the media query looks not at the CSS pixels, but at device pixels, of which there are 1280 (1024 x 125%). This occurs only in Firefox so far, because Firefox uses the device pixel ratio set by Windows, while all the other browsers (including, bizarrely, Internet Explorer) use a default device pixel ratio of 1.0. I say that this is bizarre of IE because if there is one browser that should respect Windows settings, it is IE.
Anyway, why is it this way, and how would I work around it?

You could use max-device-width to hide the column if the screen resolution is below a certain width.
This example below would trigger the display: none media query if the screen resolution is up to 1024px wide. Above 1024px gets a green div.
div {
background: #F00;
width: 100px;
height: 100px;
}
#media screen and (max-device-width: 1024px) {
div {
display: none;
}
}
#media screen and (min-device-width: 1024px) {
div {
background: green;
}
}
<div></div>

Related

media queries with min-height on iOS Safari

I'm developing a photo browser with the Bootstrap framework. It has a 4:3 aspect ratio that I'm trying to make responsive. My basic approach is something like this:
#carousel {
width: 320px;
height: 240px;
...
}
and then use media queries to support larger device widths and heights so that #carousel grows, but not any larger than the device, e.g.:
#media (min-width: 576px) and (min-height: 390px) {
#carousel {
min-width: 513px;
min-height: 385px;
border: 1px solid blue; /* test attribute */
}
}
and so forth for larger devices.
This works fine overall and in the responsive testers built into Chrome and Safari. It does not work on my physical iPhone 13, however, which has a logical width/height of 390/844px. The previous media selector should fire when the phone is in landscape, but it doesn't. iPhone 13 in landscape mode doesn't fire until a much lower min-height in the media selector:
#media (min-width: 576px) and (min-height: 300px) {
#carousel {
min-width: 513px;
min-height: 385px;
border: 1px solid blue; /* test attribute */
}
}
Note that min-height in the media selector is much lower than min-height in the CSS definition. If the height actually was 300px then the carousel should not fit on the screen, but it looks just fine. Just not very efficient or sustainable.
I suspect what's going on is that Safari is subtracting the height of its address bar and tabs from the height value. In fact I'm sure of it, because I get different behavior depending on whether I have one tab open or several. If there is only one tab open (and thus no tab bar) then I can get the media selector to fire at min-height: 333px but with multiple tabs I need to lower it to min-height: 300px. Neither one is actually correct, since if the user scrolls down in the browser then Safari hides the toolbar and makes the entire device height available (something similar happens on larger devices such as iPads).
Does anyone know how to query the effective display height from iOS Safari?
I solved this—reluctantly—with a media query condition that specifically targets the iPhone 12 Pro/13 in landscape mode:
#media (min-width: 576px) and (min-height: 300px),
(device-width: 390px) and (orientation: landscape) {
#carousel {
min-width: 513px;
min-height: 385px;
}
}
This does what I want on iOS Safari. Unfortunately, it also applies to iOS Chrome, which has a different, smaller effective screen height. I haven't figured out an even remotely elegant solution to target iOS Safari without targeting iOS Chrome.

apply zoom:80% to some browsers but not Internet Explorer

I want to fix an issue on my homepage, whereby the first image in main top carousel does not display all the content when the screen width is between 1280px and 1700px (the left texts in blue). By using css "zoom" on <section class="rotator-section"> and setting it to 80%: #media screen and (min-width: 1280px) and (max-width: 1765px){ .rotator-section {zoom:80%;}} this mostly fixes the issue between certain widths. Unfortunately, zoom does not work at all in Firefox and produces unwanted results in IE (image stays same unwanted size and rest of window shows white space).
In order, at least, to apply a good fix to Chrome, Opera, Edge and not create unwanted results in IE, I want to apply the following #media not query so that IE 10 & 11 do not apply this css:
#media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
.rotator-section {zoom:100% !important;}
}
This is not a perfect solution. As many of my website visitors use IE11, 10 & 9 & Firefox.
What is the solution for these browsers?
There is an easier way to fix this. The positioning of the background image is being caused by one bit of CSS:
#homepage-rotator>div:nth-child(2) {
background-position: right;
}
This is forcing that image to be misaligned. Try deleting that CSS, or changing it:
#homepage-rotator>div:nth-child(2) {
background-position: left;
}
I suggest you to use different images according to screen size may help you display the image properly.
Example:
/* For devices smaller than 1200px: */
body {
background-image: url('img_smallflower.jpg');
}
/* For devices 1200px and larger: */
#media only screen and (min-device-width: 1200px) {
body {
background-image: url('img_flowers.jpg');
}
}

CSS media query breakpoints are 10% larger in chrome than specified in my CSS

My CSS media query specifies a pixel range of 480-850px, but in Chrome it's kicking in from 528px-935px instead. I'm measuring pixels with chrome developer tools. I thought it might be zoom or something but zoom is set to 100%.
#media screen and (min-width: 480px) and (max-width: 850px){
#main-nav {
display: none;
}
}
Any ideas what is going on here? This media query works perfectly in Safari. Thanks for any advice.

CSS Responsive change width in 100%

ISSUE SUMMARY:
Hi,
I just purchased Jomsocial + Template Socialize. I use RSForm for my landing page.
I have an image on left and the form on the right side on desktop view.
When I reduce browser to simulate Responsive view, the text come under image but has a width of 50%. This is the width necessary for destopview.
So I add some lines in /templates/socialize/css/template.css
#media (max-width: 480px) {
.div_image_homepage_right {
width: 100% !important;
}
}
BUT it doesn't work. width stay 50% instead of 100%. I tried with Chrome & Firefox.
Please see screenshot for better understanding.
Someone has an idea how to fix that?
Try this
#media only screen and (max-width : 480px) {
.div_image_homepage_right {
width: 100% !important;
}
}
I think the underlying issue is using max-device-width vs plain old max-width. Using the "device" keyword targets physical dimension of the screen, not the width of the browser window.
For example:
#media only screen and (max-device-width: 480px) {
/* STYLES HERE for DEVICES with physical max-screen width of 480px */
}
Versus
#media only screen and (max-width: 480px) {
/* STYLES HERE for BROWSER WINDOWS with a max-width of 480px. This will work on desktops when the window is narrowed. */
}

Media queries not taking effect on browser resize

I'm using media queries to make a mobile version of a website for a client. When i resize the browser the media queries do not take effect, however they do take effect when the site is viewed on each device - i'm just curious as to why the media queries don't take effect when i resize the browser window itself i.e. Firefox.
Any input is much appreciated.
Code i'm using:
#media only screen
and (min-device-width : 320px)
and (max-device-width : 720px) {
#container {
width: 100% !important;
}
}
If you are using attribute: max-device-width or min-device-width, it will work only on devices with that width and will ignore the manual browser resizing.
You should change the attribute to: max-width / min-width.
#media screen and (min-width: 1024px){
/* some CSS here */
}
Check here:
In CSS media the difference between width and device-width can be a bit
muddled, so lets expound on that a bit. device-width refers to the
width of the device itself, in other words, the screen resolution of
the device.
http://www.javascriptkit.com/dhtmltutors/cssmediaqueries2.shtml
change your code to -
#media only screen
and (min-width : 320px)
and (max-width : 720px) {
#container {
width: 100% !important;
}
}
alternately you can keep your previous code and check the responsive nature of your website in local computer by Mozilla Responsive Design View feature - shortcut 'Control+Shift+M'

Resources