Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6985249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:39:22+00:00 2026-05-27T18:39:22+00:00

I am using the media query in css to differentiate iphone and ipad Here’s

  • 0

I am using the media query in css to differentiate iphone and ipad

Here’s my code:

/* iphone 3 */
@media only screen and (min-device-width : 320px) and (max-device-width : 480px) and (orientation:portrait) { ... }

/* iphone 4 */
@media only screen and (min-device-width : 640px) and (max-device-width : 960px) and (orientation:portrait) { ... }

/*iPad styles*/
@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) and (orientation:portrait) { ... }

/* i have the same for landscape */

Now I have a resolution conflict, the iphone 4 use the same resolution as the ipad and vice versa.

How can I fix this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:39:23+00:00Added an answer on May 27, 2026 at 6:39 pm

    Modify your iPhone 4 media query to target high density pixel displays (retina = iPhone4)

    @media screen and (max-device-width: 640px), screen and (-webkit-min-device-pixel-ratio: 2) and (orientation:portrait) { ... }
    

    Didn’t notice you reopened the question with an expansion so here is a reworked answer to target both iphones (3 and 4) and ipads.

    Breakdown of what you should expect:

    • On regular browsers you should get the teal background color.
    • orange on an ipad (landscape).
    • black on an ipad (portrait)
    • red on an iphone 4 (portrait)
    • pink on an iphone 4 (landscape)
    • green on regular smartphones, e.g Androids (landscape)
    • purple on a regular smartphone (portrait)

    CSS

    body {
        background-color:teal;
        -webkit-transition: background-color 1000ms linear;
        -moz-transition: background-color 1000ms linear;
        -o-transition: background-color 1000ms linear;
        -ms-transition: background-color 1000ms linear;
        transition: background-color 1000ms linear;
    }
    
    /* iPads (portrait and landscape) ----------- */
    @media only screen
    and (min-device-width : 768px)
    and (max-device-width : 1024px) {
        body {
            background-color:yellow;
        }
    }
    
    /* iPads (landscape) ----------- */
    @media only screen
    and (min-device-width : 768px)
    and (max-device-width : 1024px)
    and (orientation : landscape) {
        body {
            background-color:orange;
        }
    }
    
    /* iPads (portrait) ----------- */
    @media only screen
    and (min-device-width : 768px)
    and (max-device-width : 1024px)
    and (orientation : portrait) {
        body {
            background-color:black;
        }
    }
    
    /* iPhone 4 - (portrait) ---------- */
    @media
    only screen and (-webkit-min-device-pixel-ratio : 2) and (orientation:portrait),
    only screen and (min-device-pixel-ratio : 2)  and (orientation:portrait){
        body {
            background-color:red;
        }
    }
    
    /* iPhone 4 - (landscape) ---------- */
    @media screen and (-webkit-min-device-pixel-ratio : 2) and (orientation:landscape), screen and (min-device-pixel-ratio : 2) and (orientation:landscape){
        body {
            background-color:pink;
        }
    }
    
    /* Smartphones (landscape) ----------- */
    @media only screen
    and (min-width : 321px)
    and (max-width: 480px) {
        body {
            background-color:green;
        }
    }
    
    /* Smartphones (portrait) ----------- */
    @media only screen
    and (max-width : 320px) {
        body {
            background-color:purple;
        }
    }`<!-- language-all: lang-css -->
    

    I reformatted the @media queries found in this fine article over at CSS-tricks to comply to some iphone4-specific bits, but overall this media query set should cover both iphones (3 and 4 with separate media queries) and ipads as well.

    Here is a demo you can try in your i-devices.

    http://jsfiddle.net/andresilich/SpbC3/4/show/

    And you can also try out the queries over at http://quirktools.com/screenfly/ to see how they stack up. One thing though, the screenfly site does not differentiate between iphone 3 and 4 because regular browsers skip the webkit only -webkit-min-device-pixel-ratio : 1.5 pixel ratio count so you will get better results testing it out in your actual device.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently using @media screen and (-webkit-min-device-pixel-ratio:0) to target Webkit browsers + Opera
I am looking at using CSS Media Query to support multiple tablets (Android/iPad). Below
What is the advatange of using Head.js screen size detection over CSS3 media query?
I wrote these media queries for re-size my browser window @media screen and (min-width:768px)
I'm using a device that's got GPRS media to connect to a PC running
I'm developing a relatively simple website using a media query to target mobile devices
i have a sepcific question related to using CSS Media Queries. Like when we
I am using css media queries on my project to create a site that
I have a question on CSS media query.. I am implementing a HTML page
My service side code is implemented using Resteasy @GET @Path(/ad-details/{query}) @Produces(application/json) public String getAdDetails(@PathParam(query)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.