0

I am trying to apply a font and background color depending if I am using iphone 5 or 6. There is overlap in the queries, so it always falls into the last query. How do I apply CSS for iphone 5 and 6?

/*iPhone6 Portrait and Landscape*/
@media only screen 
   and (min-device-width : 375px)
   and (max-device-width : 667px) {
       body {
          background-color: red;
          font-size:16px;
       }
}

/*iPhone5 Portrait and Landscape*/
@media only screen 
    and (min-device-width : 320px)
    and (max-device-width : 568px){
        body {
            background-color: lightblue;
            font-size:12px;
        }
}
Matt Kuhns
  • 1,328
  • 1
  • 13
  • 26

1 Answers1

2

This may be helpful for you for iphone 5, iphone 6 and iphone 6+.

/* ----------- 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) { 

 }

Source : CSS-tricks

CodeRomeos
  • 2,428
  • 1
  • 10
  • 20