我试图根据我使用的是iPhone 5还是6来应用字体和背景颜色。查询中存在重叠,因此它始终属于上一个查询。如何为iPhone 5和iPhone 6应用CSS?

/*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;
        }
}

最佳答案

对于iPhone 5,iPhone 6和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) {

 }


资料来源:CSS-tricks

关于ios - @media iPhone 5和6查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32670424/

10-11 22:32
查看更多