iPhone 5横屏媒体查询

4

我看到了很多针对iPhone 5竖屏的媒体查询,但没有针对横屏模式的查询,请问有吗?我在为客户制作的网站上分别为竖屏和横屏模式添加了不同的媒体查询,并像建议的那样将iPhone 5 CSS媒体查询添加到了我的iPhone 4竖屏媒体查询中,但不确定如何处理横屏部分

@media only screen and (-webkit-min-device-pixel-ratio:1.5),only screen and (min-device-pixel-ratio:1.5),only screen (min-device-width:640px) and (max-device-width:1136px) and (-webkit-min-device-pixel-ratio:2) {
    body {
        background:#2d2928 url(images/bg960.jpg) no-repeat center top;
        background-size:480px 163px;
        font-size:96%;
        font-weight:300;
        padding:0 1%;
    }
    .logo a {
        display:block;
        margin:0 auto;
        width:260px;
        height:77px;
        background:url(images/logox2.png) no-repeat center center;
        _background:none;
        _filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/logox2.png',sizingMethod='crop');
        background-size:260px 77px;
    }
    #container {
        width:99%;
        margin:0 auto;
    }
    .frontimagewrapper {
        width:80%;
    }
    h1 {
        font-size:124%;
    }
    h2,h3,h4,h5, {
        font-family:"Trebuchet MS",Arial,Helvetica,sans-serif;
        letter-spacing:0.2em;
        font-size:100%;
    }
    .gallery h2 {
        font-size:96%;
    }
    .block h3 {
        font-size:96%;
    }
    .article h3 {
        font-size:100%;
    }
    .article h2 {
        font-size:106.6%;
    }
    p {
        font-size:0.9em;
    }
    .date {
        font-size:0.8em;
    }
    .copyright {
        font-size: 0.9em;
    }
}
/*/mediaquery*/
@media only screen and (min-device-width:320px) and (max-device-width:480px) and (orientation:landscape) and (-webkit-min-device-pixel-ratio:2) {
    body {
        font-size:96%;
    }
    .frontimagewrapper {
        width:55%;
    }
    .blogleft img {
        max-width:60%;
        height:auto;
    }
    h1 {
        font-size:150%;
    }
    h2,h3,h4,h5, {
        font-family:"Trebuchet MS",Arial,Helvetica,sans-serif;
        letter-spacing:0.2em;
        font-size:100%;
    }
    .article h2 {
        font-size:118%;
    }
    .date {
        front-size:50%;
    }
    p {
        font-size:0.9em;
        line-height:1.825em;
    }
    .date {
        font-size:0.8em;
    }
    .copyright {
        font-size: 0.9em;
    }
}
/*/mediaquery*/
2个回答

12

针对 iPhone 5 竖屏和/或横屏的媒体查询

@media only screen 
and (min-device-width : 320px) 
and (max-device-width : 568px) { 
    /* CSS here */
}

iPhone 5横屏模式的媒体查询

@media only screen 
and (min-device-width : 320px)
and (max-device-width : 568px) 
and (orientation : landscape) {
    /* CSS here */
}

6
我发现自己需要增加至767像素(比iPad少一个像素)来适配最大的Android手机。 - magzalez

0

不过,你可以根据“方向”和“-webkit-device-pixel-ratio”指定 iPhone 5 和 iPhone SE 的媒体查询。

/* Only iPhone 5 and iPhone SE(portrait mode) */
@media only screen and (min-device-width: 320px) and (max-device-width: 568px)
and (-webkit-device-pixel-ratio: 2) and (orientation:portrait)
{
    body {
        color:blue;
    }
}

/* Only iPhone 5 and iPhone SE(landscape mode) */
@media only screen and (min-device-width: 320px) and (max-device-width: 568px)
and (-webkit-device-pixel-ratio: 2) and (orientation:landscape)
{
    body {
        color:red;
    }
}
<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>Document</title>
</head>
<body>
 Hello based on the device orientation my color will change
</body>
</html>


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接