Media Querys working in desktop browsers, but not mobile - html

Works fine in any of the main 5 up to date browsers, but not on any mobile device, have no idea why.
This is my code
/* Desktop */
#import url("desktop.css");
/* Small Phone */
#import url("smallMobile.css") only screen and (max-width:320px);
/* Large Phone and small Tablet */
#import url("largeMobile-smallTablet.css") only screen and (min-width:321px) and (max-width:600px);
/* Tablet and small Desktop*/
#import url("tablet-smallDesktop.css") only screen and (min-width:601px) and (max-width:1120px);

Try
#media only screen and (min-width:321px) and (max-width:600px) {
#import url("largeMobile-smallTablet.css");
}
or
#media only screen and (min-device-width:321px) and (max-device-width:600px) {
#import url("largeMobile-smallTablet.css");
}

Use device-width and make sure you know which phones you want to target; newer iPhones have different device-pixel-ratio values which alter the device-width
Here are the media queries for different iPhones (check out more common dimensions here, https://css-tricks.com/snippets/css/media-queries-for-standard-devices/):
/* ----------- iPhone 4 and 4S ----------- */
/* Portrait and Landscape */
#media only screen
and (min-device-width: 320px)
and (max-device-width: 480px)
and (-webkit-min-device-pixel-ratio: 2) {
}
/* ----------- iPhone 5 and 5S ----------- */
/* Portrait and Landscape */
#media only screen
and (min-device-width: 320px)
and (max-device-width: 568px)
and (-webkit-min-device-pixel-ratio: 2) {
}
/* ----------- iPhone 6 ----------- */
/* Portrait and Landscape */
#media only screen
and (min-device-width: 375px)
and (max-device-width: 667px)
and (-webkit-min-device-pixel-ratio: 2) {
}
/* ----------- iPhone 6+ ----------- */
/* Portrait and Landscape */
#media only screen
and (min-device-width: 414px)
and (max-device-width: 736px)
and (-webkit-min-device-pixel-ratio: 3) {
}
And for iPads:
/* ----------- iPad 1 and 2 ----------- */
/* Portrait and Landscape */
#media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (-webkit-min-device-pixel-ratio: 1) {
}
/* ----------- iPad 3 and 4 ----------- */
/* Portrait and Landscape */
#media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (-webkit-min-device-pixel-ratio: 2) {
}

Related

Chrome emulator not the same as iPhone - better emulator?

Im building a mobile website and im not making it responsive. I am using media queries for each device. You may or may not think that is a good idea but I want to do it this way as the site is only 3 pages and very small and only accessible via mobiles.
My problem is that I need a good emulator so that I can adjust for the phones I do not own. I only have an iPhone to test and Chrome is not matching up. Is there a better emulator out there, or am I doing something wrong?
Chrome version
Actual screenshot from iPhone
Thanks.
<meta name="viewport" content="width=device-width, maximum-scale=1.0, minimum-scale=1.0, initial-scale=1.0"/>
I have solved the problem. I was redirecting from index.html using the following code:
if (screen.width < 765) {
window.location = "http://www.myaddress.com/index2.html";
}
Once I removed this code and made my index.html my mobile web site index file, the chrome emulator was the same as the actual screen.
I do not know why this happened. Somehow redirecting with the javascript has made the redirected address have a different viewport.
Where is your css sheet? Add all of this to the bottom
/* Smartphones (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
#media only screen
and (min-width : 321px) {
/* Styles */
}
/* Smartphones (portrait) ----------- */
#media only screen
and (max-width : 320px) {
/* Styles */
}
/* iPads (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
/* Styles */
}
/* iPads (landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape) {
/* Styles */
}
/* iPads (portrait) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : portrait) {
/* Styles */
}
/* Desktops and laptops ----------- */
#media only screen
and (min-width : 1224px) {
/* Styles */
}
/* Large screens ----------- */
#media only screen
and (min-width : 1824px) {
/* Styles */
}
/* iPhone 4 ----------- */
#media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* Styles */
}
/* iPhone 6 landscape */
#media only screen and (min-device-width: 375px)
and (max-device-width: 667px)
and (orientation: landscape)
and (-webkit-min-device-pixel-ratio: 2)
{ }
/* iPhone 6 portrait */
#media only screen
and (min-device-width: 375px)
and (max-device-width: 667px)
and (orientation: portrait)
and (-webkit-min-device-pixel-ratio: 2)
{ }
/* iPhone 6 Plus landscape */
#media only screen
and (min-device-width: 414px)
and (max-device-width: 736px)
and (orientation: landscape)
and (-webkit-min-device-pixel-ratio: 3)
{ }
/* iPhone 6 Plus portrait */
#media only screen
and (min-device-width: 414px)
and (max-device-width: 736px)
and (orientation: portrait)
and (-webkit-min-device-pixel-ratio: 3)
{ }
/* iPhone 6 and 6 Plus */
#media only screen
and (max-device-width: 640px),
only screen and (max-device-width: 667px),
only screen and (max-width: 480px)
{ }
/* Apple Watch */
#media
(max-device-width: 42mm)
and (min-device-width: 38mm)
{ }

Media Css for Iphone6 & Iphone6 plus

I'm making this website & I made the media settings for mobile, tablet, laptop, desktop. It looked good in all other phones. I havent' checked yet on actual tablet, but its fine on the chrome browser emulator.
However, my friend checked out the site in his Iphone6 Plus and the navbar settings were messed up. Btw, I'm using Bootstrap 3 for the framework.
I'm confused why my code is working on other phones but not on Iphone6 Plus.
Maybe even Iphone6 have the same problem?
Here is my media css:
/* Tablet (Portrait) */
#media only screen and (max-width : 768px) and (orientation: portrait) {
}
/* Phones (Portrait) */
#media only screen and (max-width : 480px) and (orientation: portrait) {
}
/* Phones (Landscape) */
#media only screen and (max-width : 480px) and (orientation: landscape){
}
/* Tablet (Landscape)*/
#media only screen and (max-width :1100px) and (orientation: landscape) {
}
/* Medium Devices, Desktops and tablet landscape*/
#media only screen and (min-width : 992px) {
}
/* Large Screens, Large Desktops */
#media only screen and (min-width : 1601px) {
}
I already checked online that the pixel density & resolution is quite different for Iphone6 Plus. We've tried the solution from here : iPhone 6 and 6 Plus Media Queries
So far, even those queries didn't fix our problem. It seems like there were no changes. I hope this problem could be resolved quickly, I appreciate your help.
Everything comes down to device-pixel-ratio which used to be 2x for iphones. New iphone 6 plus has 3x retina display
/* iPhone 6 landscape */
#media only screen and (min-device-width: 375px)
and (max-device-width: 667px)
and (orientation: landscape)
and (-webkit-min-device-pixel-ratio: 2)
{
/* Your CSS */
}
/* iPhone 6 portrait */
#media only screen
and (min-device-width: 375px)
and (max-device-width: 667px)
and (orientation: portrait)
and (-webkit-min-device-pixel-ratio: 2)
{
/* Your CSS */
}
/* iPhone 6 Plus landscape */
#media only screen
and (min-device-width: 414px)
and (max-device-width: 736px)
and (orientation: landscape)
and (-webkit-min-device-pixel-ratio: 3)
{
/* Your CSS */
}
/* iPhone 6 Plus portrait */
#media only screen
and (min-device-width: 414px)
and (max-device-width: 736px)
and (orientation: portrait)
and (-webkit-min-device-pixel-ratio: 3)
{
/* Your CSS */
}
/* iPhone 6 and 6 Plus */
#media only screen
and (max-device-width: 640px),
only screen and (max-device-width: 667px),
only screen and (max-width: 480px)
{
/* Your CSS */
}
Further more, an article from CSS | MDN to add more browsers support and a fallback.
link : https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries
#media (-webkit-min-device-pixel-ratio: 2), /* Webkit-based browsers */
(min--moz-device-pixel-ratio: 2), /* Older Firefox browsers (prior to Firefox 16) */
(min-resolution: 2dppx), /* The standard way */
(min-resolution: 192dpi) /* dppx fallback */
A list of devices with their respective device-pixel-ratio.
link : https://bjango.com/articles/min-device-pixel-ratio/

Fit website on iphone and ipad screen viewport?

Before Apple released the last iOS update 9.3.1 on March 2016, all my webistes use to fit within the screen of an iphone (landscape mode) and ipad (portrait and landscape).
After the release, my sites appear zoomed and I have to swipe in/out in order to make the website fit the entire screen again. I tried many things that I found on different forums but none helped...
The tag <meta name="viewport" content="width=device-width, initial-scale=1"> use to make it, and suddenly stopped working. Any idea?
You can see an example at www.buenosaireshelicopter.com
See site after iOS 9.3.1 update
See site before iOS 9.3.1 update
I use this for my websites. It may be overkill, but I've never had a problem.
/* Smartphones (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
#media only screen
and (min-width : 321px) {
/* Styles */
}
/* Smartphones (portrait) ----------- */
#media only screen
and (max-width : 320px) {
/* Styles */
}
/* iPads (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
/* Styles */
}
/* iPads (landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape) {
/* Styles */
}
/* iPads (portrait) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : portrait) {
/* Styles */
}
/* Desktops and laptops ----------- */
#media only screen
and (min-width : 1224px) {
/* Styles */
}
/* Large screens ----------- */
#media only screen
and (min-width : 1824px) {
/* Styles */
}
/* iPhone 4 ----------- */
#media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* Styles */
}
/* iPhone 6 landscape */
#media only screen and (min-device-width: 375px)
and (max-device-width: 667px)
and (orientation: landscape)
and (-webkit-min-device-pixel-ratio: 2)
{ }
/* iPhone 6 portrait */
#media only screen
and (min-device-width: 375px)
and (max-device-width: 667px)
and (orientation: portrait)
and (-webkit-min-device-pixel-ratio: 2)
{ }
/* iPhone 6 Plus landscape */
#media only screen
and (min-device-width: 414px)
and (max-device-width: 736px)
and (orientation: landscape)
and (-webkit-min-device-pixel-ratio: 3)
{ }
/* iPhone 6 Plus portrait */
#media only screen
and (min-device-width: 414px)
and (max-device-width: 736px)
and (orientation: portrait)
and (-webkit-min-device-pixel-ratio: 3)
{ }
/* iPhone 6 and 6 Plus */
#media only screen
and (max-device-width: 640px),
only screen and (max-device-width: 667px),
only screen and (max-width: 480px)
{ }
/* Apple Watch */
#media
(max-device-width: 42mm)
and (min-device-width: 38mm)
{ }

How to set separate media queries to effect the same element?

I am trying to optimize my mobile webpage experience throughout several iPhone screens, particularly the 5/5s and 6/6s. I'm trying to effect the position attribute of an element in a different way depending on the screen i.e, "if the screen is a 5/5s, do this", "if the screen is a 6/6s, do this". However, one query just overrides the other instead of doing its own specific thing.
Here is my CSS:
/* for iPhone 6/6S */
#media (max-width:730px) {
.fore-man {
top: 1100px;
}
/* for iPhone 5/5S */
#media (max-width:560px) {
.fore-man {
top: 1100px;
}
How do I correct it to be screen specific & not just override the previous query?
Would adding a min width to your 6/6s query do the trick?
/* for iPhone 6/6S */
#media (max-width:730px) and (min-width: 561px) {
.fore-man {
top: 1100px;
}
}
/* for iPhone 5/5S */
#media (max-width:560px) {
.fore-man {
top: 1100px;
}
}
According to this article, targeting device screens is better done with device-width properties.
Take a look, here
/* ----------- iPhone 5 and 5S ----------- */
/* Portrait and Landscape */
#media only screen
and (min-device-width: 320px)
and (max-device-width: 568px)
and (-webkit-min-device-pixel-ratio: 2) {
}
/* Portrait */
#media only screen
and (min-device-width: 320px)
and (max-device-width: 568px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: portrait) {
}
/* Landscape */
#media only screen
and (min-device-width: 320px)
and (max-device-width: 568px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: landscape) {
}
/* ----------- iPhone 6 ----------- */
/* Portrait and Landscape */
#media only screen
and (min-device-width: 375px)
and (max-device-width: 667px)
and (-webkit-min-device-pixel-ratio: 2) {
}
/* Portrait */
#media only screen
and (min-device-width: 375px)
and (max-device-width: 667px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: portrait) {
}
/* Landscape */
#media only screen
and (min-device-width: 375px)
and (max-device-width: 667px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: landscape) {
}
/* ----------- iPhone 6+ ----------- */
/* Portrait and Landscape */
#media only screen
and (min-device-width: 414px)
and (max-device-width: 736px)
and (-webkit-min-device-pixel-ratio: 3) {
}
/* Portrait */
#media only screen
and (min-device-width: 414px)
and (max-device-width: 736px)
and (-webkit-min-device-pixel-ratio: 3)
and (orientation: portrait) {
}
/* Landscape */
#media only screen
and (min-device-width: 414px)
and (max-device-width: 736px)
and (-webkit-min-device-pixel-ratio: 3)
and (orientation: landscape) {
}

Bootstrap Media queries Orientation Change to Landscape not working under Physical Device

I am facing one very strange issue in bootstrap, basically I have this page http://excellencewebworks.com/bootstrap/video_skin.html
Here I am adding video covered with a tablet video skin. When I check the page under responsive mode in Mozilla Firefox -> Tools-> Responsive Design View for 360 x 640 dimension it works good under portrait and landscape mode.
But when checking the same page in physical device, it works only in portrait and not landscape, design gets altered in landscape mode. Strange to see this.
Can anyone please look into this and let me know what I am doing wrong here?
Thanks,
Ronak Shah
Here is code for landscape and portrait mode media queries try this.
/* ----------- iPhone 4 and 4S ----------- */
/* Portrait and Landscape */
#media only screen
and (min-device-width: 320px)
and (max-device-width: 480px)
and (-webkit-min-device-pixel-ratio: 2) {
}
/* Portrait */
#media only screen
and (min-device-width: 320px)
and (max-device-width: 480px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: portrait) {
}
/* Landscape */
#media only screen
and (min-device-width: 320px)
and (max-device-width: 480px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: landscape) {
}
/* ----------- iPhone 5 and 5S ----------- */
/* Portrait and Landscape */
#media only screen
and (min-device-width: 320px)
and (max-device-width: 568px)
and (-webkit-min-device-pixel-ratio: 2) {
}
/* Portrait */
#media only screen
and (min-device-width: 320px)
and (max-device-width: 568px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: portrait) {
}
/* Landscape */
#media only screen
and (min-device-width: 320px)
and (max-device-width: 568px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: landscape) {
}
/* ----------- iPhone 6 ----------- */
/* Portrait and Landscape */
#media only screen
and (min-device-width: 375px)
and (max-device-width: 667px)
and (-webkit-min-device-pixel-ratio: 2) {
}
/* Portrait */
#media only screen
and (min-device-width: 375px)
and (max-device-width: 667px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: portrait) {
}
/* Landscape */
#media only screen
and (min-device-width: 375px)
and (max-device-width: 667px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: landscape) {
}
/* ----------- iPhone 6+ ----------- */
/* Portrait and Landscape */
#media only screen
and (min-device-width: 414px)
and (max-device-width: 736px)
and (-webkit-min-device-pixel-ratio: 3) {
}
/* Portrait */
#media only screen
and (min-device-width: 414px)
and (max-device-width: 736px)
and (-webkit-min-device-pixel-ratio: 3)
and (orientation: portrait) {
}
/* Landscape */
#media only screen
and (min-device-width: 414px)
and (max-device-width: 736px)
and (-webkit-min-device-pixel-ratio: 3)
and (orientation: landscape) {
}
Ok, Give it a try something like this :
#media screen and (min-width:360px) and (max-width:640px){
/*-----style----*/
}
Also make sure your media queries are not overlapping.