Creating personalized CSS styles specifically designed for iPad Mini 2 with a retina display and optimizing it for different screen/viewport settings

Struggling to assign different colors for various screen sizes, I'm facing a perplexing issue with the iPad Mini 2's Retina Display. Despite its pixel resolution, it doesn't conform to the specified rules and I'm left wondering why.

This is the code I am using:

/** Retina iPad **/
@media
screen and (-webkit-min-device-pixel-ratio: 1.5),
screen and (-moz-min-device-pixel-ratio: 1.5),
screen and (-o-min-device-pixel-ratio: 1.5),
screen and (min-device-pixel-ratio: 1.5){
    body {
        background-color: #486ffd;
    }
}
/** 1600px non-retina screen **/
@media screen and (max-width: 1600px){
    body {
        background-color: #770029;
    }
}
/** 1000px non-retina screen **/
@media screen and (max-width: 1000px){
    body {
        background-color: #117700;
    }
}
/** 500px non-retina screen **/
@media screen and (max-width: 500px){
    body {
        background-color: #ffce00;
    }
}
/** 300px non-retina screen **/
@media screen and (max-width: 300px){
    body {
        background-color: #770200;
    }
}

In portrait mode, my iPad Mini 2 displays background color #117700, while in landscape mode it shows #770029. How does it not adhere to its resolution of 2048x1536?

My HTML also includes:

<meta name="viewport" content="width=device-width; initial-scale=1; maximum-scale=3;" />

I've attempted both pixel ratios of 1.5 and 2 as suggested by others, but haven't found a solution yet. Any suggestions?

The website in question can be found here if you'd like to investigate further.

Answer №1

The issue was resolved by rearranging the CSS specifications in the correct sequence.

When selectors have the same level of specificity, the most recent rule takes precedence.

I also included:

only screen and (min-resolution: 192dpi)
only screen and (min-resolution: 2dppx)

To further refine and specify it.

/** 1600px non-retina screen **/
@media screen and (max-width: 1600px){
    body {
        background-color: #770029;
    }
}

/** Retina iPad **/
@media
only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and (-moz-min-device-pixel-ratio: 2),
only screen and (-o-min-device-pixel-ratio: 2/1),
only screen and (min-device-pixel-ratio: 2),
only screen and (min-resolution: 192dpi),
only screen and (min-resolution: 2dppx){
    body {
        background-color: #486ffd;
    }
}

Therefore, the correct order is: LATEST overrides FIRST, meaning device-width should be overridden by the retina specifics. More information on this topic can be found here CSS Specificity

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

Nested Divs in CSS

I'm really struggling to get a div to display under another div in the way they usually do. Currently, I am using MaterializeCSS for my layout setup: <div class="container valign-wrapper"> <div class="customClass"></div> &l ...

Transform the appearance of the datepicker with jquery-ui

Is it possible to customize the appearance of the calendar using css files from jquery-ui? <input type="text" id="dob"/> Check out this script: $(document).ready(function(){ $("#dob").datepicker(); }); See an example here. How can I style it ...

The integration of jQuery in PHP is experiencing some technical challenges

There's one issue driving me crazy: I created a left-floating file tree view and included it in my website. However, when I include my website in the file treeview, it becomes unclickable in Chrome, and in IE 9, the thumbnail part for viewing PDF docu ...

Switching between states using JavaScript

Here is a code snippet I'm working with: <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="C:\Users\rapandey\Documen ...

Is there a way to dynamically adjust the height of a Materialize Slider based on its content?

Currently, I am working on a project utilizing the Materialize framework, specifically implementing its slider feature. However, I have encountered an issue regarding adjusting the height of the slider dynamically based on the content it contains. Is there ...

`Implementing AJAX data binding in a Flask Python Application`

I am currently laying the groundwork for my first Python Flask web application. While I have the server-side details sorted out, I have some queries regarding the client-side implementation. The application I am working on will be a single-page applicatio ...

How to use TypeScript to modify button styling with an OnClick() event handler

Learning TypeScript with Existing Code Transition Currently, I am delving into the world of TypeScript and in the process of converting my CoffeeScript code to TypeScript (specifically Lit Web Component). Confusion on Translation Process I'm encount ...

Creating a custom video to use as the favicon for my website

Imagine this: With the help of this plugin, you can have a video playing as your site's favicon using the following code snippet: var favicon=new Favico(); var video=document.getElementById('videoId'); favicon.video(video); //stop favicon.v ...

Angular 4 allows the addition of an image from right to left upon clicking

I've been working on angular 4 and I've successfully implemented the functionality of adding flags. However, the issue is that the flags are currently appearing from left to right. What I'm aiming for is to have the images appear from right ...

Measure with an "em" unit indicated by a dot

Could you clarify if there is a distinction between writing padding:.6em and padding:0.6em; and if they have the same value, why not just use padding:0.6em; ? Thank you ...

Utilizing ID's within a jade template embedded within a P HTML element

Using the jade template, I successfully formed this paragraph. My next step is to add an ID or a class around the word stackoverflow. How can I achieve this in jade? I am aware that in regular HTML we would use something like <div class="className"> ...

Challenges related to maintaining a webpage's content using AJAX

I have a form that I want to use to send and insert the values into my database. After the values are inserted, I would like to clear the input fields of the form and display a success message. Here's an example of how I would like it to look: Clear ...

`Why is my table row not appearing horizontally in Cordova/Phonegap?`

Why is my tr tag displaying buttons vertically instead of horizontally? A similar code works properly on jsfiddle What am I doing wrong? Here is my HTML: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="form ...

Utilize PHP for loop to output form values into XML format

Hey there, I'm currently facing an issue with setting up a for loop in PHP to transfer the content of an HTML form into an XML file. It works perfectly fine without the for loop, but throws errors when included. Can anyone provide some insights? It&ap ...

Changing the bootstrap popover location

I'm looking to customize the position of a Bootstrap popover that appears outside of a panel. Here's my setup: HTML: <div class="panel"> <div class="panel-body"> <input type="text" id="text_input" data-toggle="popover ...

Incorporate a 'Select All' functionality into ion-select by adding a dedicated button

Looking for a way to set custom buttons on ion-select through interfaceOptions in ionic 4? HTML <ion-item> <ion-label>Lines</ion-label> <ion-select multiple="true" [(ngModel)]="SelectedLines" [interfaceOptions]="customAlertOption ...

In what ways can CSS be used to create a smoother edge effect on images?

After attempting to add an image to my website, I noticed that its edges appear quite rough. https://i.sstatic.net/Xol9R.png(Note: In the image above, you can observe the jagged surface around the berry). This issue arose when I eliminated the background ...

Unable to locate CSS/SCSS Code module in VSCode when using a relative path

I am currently developing a SharePoint Framework web-part in VS Code. Despite my efforts, I am unable to locate my scss styles file, even though it is stored in the same directory - please refer to the image provided below: https://i.sstatic.net/LanF7.pn ...

What is the best way to transfer the window object from the current tab to the extension?

I am looking to retrieve user storage data (local and session) from a specific tab, similar to what is shown in this app (see screen below). From my understanding, I need to access the window object of the active tab. While I have obtained the object, I a ...

"Unveiling the invisible: Revealing hidden characters in PHP

Currently I am dealing with some code extracted from a MySQL column. Within this code are hidden characters like "\t" and "\n". I am attempting to showcase the raw code in a DIV while also making sure these hidden characters are visible. The cod ...