Troubleshooting CSS media queries on iOS devices

My media queries are set up to target different iOS devices such as iPad3, iPad2, iPhone4, and iPhone3. However, when I load the page with an iPhone3 and an iPad2, the correct divs are styled correctly. But when I load it with an iPad3, the styles for iPad2 and iPhone4 are applied, but not for iPad3. Any suggestions on what might be causing this issue? (I'm unable to test the iPhone4 at the moment.)

<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
<link rel="stylesheet" href="ipad3.css" media="only screen and (min-device-width:1536px) and (max-device-width:2048px) and (-webkit-min-device-pixel-ratio:2)" type="text/css" />
<link rel="stylesheet" href="ipad2.css" media="only screen and (min-device-width:768px) and (max-device-width:1024px) and (-webkit-min-device-pixel-ratio:0)" type="text/css" />
<link rel="stylesheet" href="iphone4.css" media="only screen and (min-device-width:640px) and (max-device-width:960px) and (-webkit-min-device-pixel-ratio:2)" type="text/css" />
<link rel="stylesheet" href="iphone3.css" media="only screen and (min-device-width:320px) and (max-device-width:480px) and (-webkit-min-device-pixel-ratio:0)" type="text/css" />
</head>

<body>
<div id="ipad3" style="width:200px;height:200px;border:1px solid black"></div>
<div id="ipad2" style="width:200px;height:200px;border:1px solid black"></div>
<div id="iphone4" style="width:200px;height:200px;border:1px solid black"></div>
<div id="iphone3" style="width:200px;height:200px;border:1px solid black"></div>

ipad3 should be RED
<br>
ipad2 should be GREEN
<br>
iphone4 should be BLUE
<br>
iphone3 should be ORANGE
</body>
</html>

Each of the css files (#iPad3 { background-color: red; } is coded accordingly to match their respective device.

Answer №1

When setting the width of the viewport to device-width, the iPad3 screen resolution may still be reported as 1024x768, but the device-pixel-ratio will be 2.

Answer №2

If you're looking to specifically target the iPad 3, consider using this CSS snippet:

<link rel="stylesheet" href="ipad3.css" media="only screen and (min-device-width:768px) and (max-device-width:1024px) and (-webkit-min-device-pixel-ratio:1.5)" type="text/css" />

While the pixel dimensions remain constant, the pixel ratio differs from that of the original iPad and the iPad 2.

Answer №3

Hey Robbo, it seems like your code contains the line -webkit-min-device-pixel-ratio:0, which is incorrect syntax. Non-retina devices typically have a pixel ratio of 1, which might explain why the iPad 3 is loading both stylesheets.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with mouse hover not triggering overlay effect between two div elements

I am trying to display articles in a 2x3 matrix with article details like image, title, author, and description wrapped inside a div. I want this entire div to be overlapped by another div of the same dimensions containing a single image. Below is a snipp ...

Looking for solutions to streamline the deployment of your JavaScript, CSS, and HTML files automatically?

Is there a tool for automating my project workflow to manage the folder structure below on Mac? During the build process, use project.js but deploy only project.min.js Use project.less during the build process, but deploy only project.min.css Or do I ne ...

Using Swift to extract information from an NSDictionary

I have a code snippet that reads data from an NSDictionary: let itemsArray: NSArray = response.objectForKey("items") as! NSArray; let nextPageToken: String = response.objectForKey("nextPageToken") as! String var videoIdArray: [String] = [] for (item) in ...

Tips for adjusting image dimensions specifically for mobile viewing

My website's image sizes are perfectly set for desktop, but they do not appear responsive in mobile mode. Despite using Bootstrap, the images overflow the display size. How can I set different image sizes for mobile mode? The same issue applies to the ...

Stop the default drag behavior on an input range element in VueJS

Is there a way to disable the default drag functionality of an input range element without affecting the click feature? Users should be able to change values by clicking instead of dragging. <input type="range" min="0" max=& ...

Switch up the text when the image link is being hovered over

Is there a way to change the text color of the "a" tag when it is not wrapping the img link? <li> <a href="# WHEN I HOVER THIS IMG LINK I WANT A TAG BELOW TO CHANGE COLOR"> <img alt="Franchise 16" src="#"></img> < ...

Create a visual layout showcasing a unique combination of images and text using div elements in

I created a div table with 3 images and text for each row, but I'm struggling to make all the text-containing divs uniform in size. How can I achieve this? Also, I need to center this table on the screen, and currently using padding to do so. Is there ...

Curious about the thumbnail icon in mobile Chrome? Find out how you can incorporate it into your website!

I'm seeking assistance in identifying the name of this icon and how to properly implement it on my website. Any guidance would be greatly appreciated. https://i.sstatic.net/GoA6o.jpg ...

Choosing a sibling element before another using CSS

Is there a way to make both of my icons display some text when hovered over? I managed to make it work, but the leftmost icon doesn't trigger the span element when hovered. The text needs to appear on the left side of the Yelp icon for design reasons. ...

React-bootstrap's Modal is glitching and only partially appearing on the screen

I am a beginner in frontend development and I've been struggling to position the modal at the center of the screen; it keeps appearing on the right side. I am currently using "bootstrap/dist/css/bootstrap.min.css" for my CSS. Should I create a new CSS ...

Replace the single text area with multiple div elements and update the image within each div

Within the 'Pinctitle' area, there is text that I want to change each time a Pselectorbutton is hovered over with a fading effect. Additionally, I would like the image inside the 'Pselectorbutton' to change at the same time. Currently, ...

Is it possible to utilize the viewController's view in NSObject?

codeFile.h @interface connectionServer : NSObject<MBProgressHUDDelegate> { MBProgressHUD *HUD; } codeFile.m -(void) displayHud:(NSString*)text{ HUD = [[MBProgressHUD alloc] initWithView:self.view]; // initialization [self.view addSub ...

iOS compatibility issue preventing React Native app from functioning

Hey there, I recently downloaded a sample app from https://github.com/iZaL/my-appointment. However, when I try to run it, I encounter an error in my-appointment-master/src/containers/Category/Category.js: It says "Unable to find this module in its module m ...

CSS elements unexpectedly remain in line

I have encountered an issue with a navigation bar on one of my website projects. The HTML elements I am trying to add afterwards are not aligning properly with the navbar. I have thoroughly checked for any open HTML tags, syntax errors, or conflicting CSS ...

How to vertically align a div inside another div

My Goal: Ensuring that the divs with "col-md-1" (the vote total and vote arrows) are vertically aligned in the center of the parent div HTML Structure: <div class="row container-fluid"> <div class="col-md-1 centered-div"> <p id ...

"The space between the header-main section and the main-footer section is pure white

I'm facing an issue with the white space between the header-main and main-footer sections. I would like to either match their color to the rest of the website or completely remove the space. The color I want to use is #fefcf5. I hope this edited versi ...

What is the best way to include a span within a select option element to display a flag beside each option?

I'm currently working on a dropdown menu that allows users to easily select their preferred language. I'm facing an issue with incorporating flags using https://github.com/lipis/flag-icon-css for each option. Can someone please assist me with thi ...

The script ceased functioning immediately following the inclusion of a case-insensitive search feature and interactive images

In the process of creating my inaugural project featuring a collection of images, I wanted to include a filter/search bar at the top. This bar would dynamically filter the displayed pictures based on user input. For example, typing "Aatrox" into the search ...

Is it possible to comment out classes within a specified class attribute? How can this be achieved?

Is there a way to temporarily omit specific classes within HTML (<div class="" ...>)? For instance: <div data-group="group1" data-container="true" class="container-lg d-flex /* slider */ p-0"> In this s ...

What could be causing the empty space along the right edge of my website?

I've encountered an issue with my website where there's a white space on the right side of the page, causing horizontal scrolling. I attempted to resolve this by adding overflow: hidden to the CSS, which worked perfectly in Chrome. However, the p ...