I have like 16 media queries or something and i noticed that if i put every media query portrait 1 different color some are falling under another media query. For instance i have:
#media only screen and (min-device-width: 320px) and (max-device-width: 480px) and (-webkit-min-device-pixel-ratio: 2) and (orientation: portrait) {}
and i have for instance:
#media only screen and (min-device-width: 320px) and
(max-device-width: 568px) and (-webkit-min-device-pixel-ratio: 2)
and (orientation: portrait) {}
Then both backgrounds are red but i put the second background on purple. I am referring to my own website www.gester.nl. Can someone help me and see into the website with media query code why some media queries are not working like they are supposed to work. Is it that i use a wrong order or something? I just use google f12 to see how it looks on other devices.
Your media queries are overlapping. You will want to use something like the below to target specific screen sizes:
#media only screen and (min-width: 320px) and (max-width: 480px) {
// do stuff between 320px and 480px
}
#media only screen and (min-width: 481px) and (max-width: 568px) {
// do stuff between 481px and 568px
}
From Large Desktop Screen to Small Mobile Device: which are the Media Queries we should use?
I am bit confused with this. I am trying to get this clearly
/*Small Desktop*/
#media (max-width:1920px){
}
#media queries apply standard CSS only where the device's screen meets certain defined criteria (height, width, and pixel-ratio; mainly)
The best resource I've found for media queries is https://css-tricks.com/snippets/css/media-queries-for-standard-devices/
Here's a snippet of the fantastic work there:
/* ----------- iPad mini ----------- */
/* Portrait and Landscape */
#media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (-webkit-min-device-pixel-ratio: 1) {
}
/* Portrait */
#media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (orientation: portrait)
and (-webkit-min-device-pixel-ratio: 1) {
}
/* Landscape */
#media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (orientation: landscape)
and (-webkit-min-device-pixel-ratio: 1) {
}
I have these two but they are not working. I'm simulating in Chrome
/* Landscape*/
#media only screen and (min-device-width: 1024px) and (max-device-width: 1366px) and (-webkit-min-device-pixel-ratio: 2) and (orientation: landscape) {}
/* Portrait*/
#media only screen and (min-device-width: 1024px) and (max-device-width: 1366px) and (-webkit-min-device-pixel-ratio: 2) and (orientation: portrait) {}
If I remove 'and (orientation: landscape)' then the css in there works in the first media query.
What is the correct orientation, for both landscape and portrait ?
The HTML meta is set as
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
/* ----------- iPad Pro ----------- */
/* Portrait and Landscape */
#media only screen
and (min-width: 1024px)
and (max-height: 1366px)
and (-webkit-min-device-pixel-ratio: 1.5) {
}
/* Portrait */
#media only screen
and (min-width: 1024px)
and (max-height: 1366px)
and (orientation: portrait)
and (-webkit-min-device-pixel-ratio: 1.5) {
}
/* Landscape */
#media only screen
and (min-width: 1024px)
and (max-height: 1366px)
and (orientation: landscape)
and (-webkit-min-device-pixel-ratio: 1.5) {
}
I don't have an iPad Pro but this works for me in the Chrome simulator.
/* Landscape*/
#media only screen and (min-device-width: 1366px) and (max-device-height: 1024px) and (-webkit-min-device-pixel-ratio: 2) and (orientation: landscape) {}
/* Portrait*/
#media only screen and (min-device-width: 1024px) and (max-device-height: 1366px) and (-webkit-min-device-pixel-ratio: 2) and (orientation: portrait) {}
Portrait medias query for iPad Pro should be fine as it is.
Landscape media query for iPad Pro (min-device-width) should be 1366px and (max device-height) should be 1024px.
Hope this helps.
Note that there are multiple iPad Pros, each with a different Viewports: When emulating an iPad Pro via the Chrome developer tools, the iPad Pro (12.9") is the default option. If you want to emulate one of the other iPad Pros (10.5" or 9.7") with a different viewport, you'll need to add a custom emulated device with the correct specs.
You can search devices, viewports, and their respective CSS media queries at: http://vizdevices.yesviz.com/devices.php.
For instance, the iPad Pro (12.9") would have the following media queries:
/* Landscape */
#media only screen and (min-width: 1366px) and (orientation: landscape) { /* Your Styles... */ }
/*Portrait*/
#media only screen and (min-width: 1024px) and (orientation: portrait) { /* Your Styles... */ }
Whereas the iPad Pro (10.5") will have:
/* Landscape */
#media only screen and (min-device-width: 1112px) and (orientation: landscape) { /* Your Styles... */ }
/*Portrait*/
#media only screen and (min-device-width: 834px) and (orientation: portrait) { /* Your Styles... */ }
I can't guarantee that this will work for every new iPad Pro which will be released but this works pretty well as of 2019:
#media only screen and (min-width: 1024px) and (max-height: 1366px)
and (-webkit-min-device-pixel-ratio: 1.5) and (hover: none) {
/* ... */
}
This worked for me
/* Portrait */
#media only screen
and (min-device-width: 834px)
and (max-device-width: 834px)
and (orientation: portrait)
and (-webkit-min-device-pixel-ratio: 2) {
}
/* Landscape */
#media only screen
and (min-width: 1112px)
and (max-width: 1112px)
and (orientation: landscape)
and (-webkit-min-device-pixel-ratio: 2)
{
}
Too late but may this save you from headache!
All of these is because we have to detect the target browser is a mobile!
Is this a mobile then combine it with min/max-(width/height)'s
So Just this seems works:
#media (hover: none) {
/* ... */
}
If the primary input mechanism system of the device cannot hover over elements with ease or they can but not easily (for example a long touch is performed to emulate the hover) or there is no primary input mechanism at all, we use none!
There are many cases that you can read from bellow links.
Described as well Also for browser Support See this from MDN
I tried several of the proposed answers but the problem is that the media queries conflicted with other queries and instead of displaying the mobile CSS on the iPad Pro, it was displaying the desktop CSS. So instead of using max and min for dimensions, I used the EXACT VALUES and it works because on the iPad pro you can't resize the browser.
Note that I added a query for mobile CSS that I use for devices with less than 900px width; feel free to remove it if needed.
This is the query, it combines both landscape and portrait, it works for the 12.9" and if you need to target the 10.5" you can simply add the queries for these dimensions:
#media only screen and (max-width: 900px),
(height: 1024px) and (width: 1366px) and (-webkit-min-device-pixel-ratio: 1.5) and (orientation: landscape),
(width: 1024px) and (height: 1366px) and (-webkit-min-device-pixel-ratio: 1.5) and (orientation: portrait) {
// insert mobile and iPad Pro 12.9" CSS here
}
For those who want to target an iPad Pro 11" the device-width is 834px, device-height is 1194px and the device-pixel-ratio is 2. Source: screen.width, screen.height and devicePixelRatio reported by Safari on iOS Simulator.
Exact media query for portrait: (device-height: 1194px) and (device-width: 834px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)
iPad Pro 12th Gen - 2022, I have tried, and it worked.
Portrait:
#media only screen and (width: 1024px) and (height: 1292px) {}
Landscape:
#media only screen and (width: 1366px) and (height: 950px) {}
I am developing one website for mobiles and tablets. for iPhone 5 i am using
#media only screen
and (max-device-width: 320px)
and (orientation: portrait) {}
and
#media only screen
and (min-device-width: 568px)
and (orientation : landscape) {}
and for ipad I am using
link rel="" media="all and (device-width: 768px) and (device-height: 1024px) and (orientation:landscape)" href=""
link rel="" media="all and (device-width: 768px) and (device-height: 1024px) and (orientation:portrait )" href=""
but both are merging , don't know how.
Is there any other way to use ?
Use only '#media screen and (max-width: Xpx)' at the bottom of your css file.
This Chrome app https://chrome.google.com/webstore/detail/window-resizer/kkelicaakdanhinjdeammmilcgefonfh will give you all the most common screen sizes for you to auto resize your browser windows.
Just use a number a little larger than the screen width, to have a margin of error, and you are good to go.
I like to use:
#media screen and (max-width: 1100px){}
#media screen and (max-width: 660px){}
#media screen and (max-width: 500px){}
#media screen and (max-width: 400px){}
I had a concern. I'm putting together a little site and for some reason my iphone and ipad media queries are colliding. The Iphone picks up on Ipad styles, but not vice versa. So I wanted to put what I'm using out there and see if anyone can help.
thanks guys.
#media screen and (max-device-width: 480px), screen and (-webkit-min-device-pixel-ratio: 2) //iphone
#media screen and (max-device-width: 480px) and (orientation:landscape) //iphone landscape
#media screen and (max-device-width: 1024px) and (orientation:landscape) //ipad landscape
#media screen and (max-device-width: 768px) and (orientation:portrait) //ipad portrait
I pulled these from a few tutorials that seemed pretty legit, any ideas why the styles are leaking?
You're using max-device-width which will include iphone as well. Should be:
#media screen and (max-device-width: 480px), screen and (-webkit-min-device-pixel-ratio: 2) //iphone
#media screen and (max-device-width: 480px) and (orientation:landscape) //iphone landscape
#media screen and (min-device-width: 1024px) and (orientation:landscape) //ipad landscape
#media screen and (min-device-width: 768px) and (orientation:portrait) //ipad portrait
notice the min-device-width