如何在横向位置编写高清/视网膜显示的媒体查询?

时间:2013-07-10 16:18:23

标签: css css3 media-queries

基本上我有两种不同的风格,我想在移动设备上制定。一套用于纵向视图,另一套用于横向。我在测试过程中遇到了一个问题,因为它的分辨率很高,我的Galaxy S4在Portrait View中显示了我的景观视图。我的初始CSS编写如下。

#checkoutoptions {
    border: 2px solid #c6c6c6;
    border-radius: 10px;
    padding: 10px;
    position: relative;
}

#checkoutoptions h3 {
    font-size: 1.2em;
    font-weight: 500;
    margin-left: 35px;
    margin-top: 10px;
}

#checkoutoptions h4 {
    color: #000;
    font-size: 1.2em;
    font-weight: 600;
    margin-bottom: 0;
}

#checkoutoptions p {
    font-size: .8em;
    margin-bottom: 5px;
}

#checkoutoptions .label {
    display: inline-block;
    font-size: .9em;
    margin: 10px 0 20px;
}

#checkoutoptions .input {
    border: 1px solid #eee;
    border-radius: 5px;
    box-shadow: 0 0 0 4px #f4f4f4;
    font-size: 1em;
    height: 2.25em;
    margin-top: 10px;
}

#checkoutoptions .number {
    background-color: #c6c6c6;
    border-radius: 15px;
    color: #fff;
    height: 30px;
    line-height: 30px;
    position: absolute;
    text-align: center;
    top: 15px;
    width: 30px;
}

#checkoutoptions .dividingLine {
    border-bottom: 1px solid #c6c6c6;
    padding-bottom: 10px; 
}

#checkoutoptions #signin {
    border-bottom: 1px solid #c6c6c6;
    padding-bottom: 10px; 
}

#checkoutoptions .forgotpassword {
    font-size: .75em;
    margin-top: 15px;
}

@media only screen and (min-width: 321px){
    #checkoutoptions {
        overflow: auto;
    }

    #signin {
        float: left;
        clear: both;
        width: 45%;
    }

    .registeroptions { 
        float: left;
        position: relative;
        width: 50%;
    }

    #checkoutoptions #signin {
        border-bottom: 0;
        padding-bottom: 0; 
        border-right: 1px solid #c6c6c6;
        margin-right: 10px;
    }
}

通过一些研究,我发现有可用于HD / Retina屏幕的媒体查询。所以我添加了以下内容:

@media
only screen and (-webkit-min-device-pixel-ratio: 1.25),
only screen and ( min--moz-device-pixel-ratio: 1.25),
only screen and ( -o-min-device-pixel-ratio: 1.25/1),
only screen and ( min-device-pixel-ratio: 1.25),
only screen and ( min-resolution: 200dpi),
only screen and ( min-resolution: 1.25dppx)
{
    #checkoutoptions {
        overflow: auto;
    }

    #signin {
        float: none;
        clear: both;
        width: 100%;
    }

    .registeroptions { 
        float: none;
        position: relative;
        width: 100%;
    }

    #checkoutoptions #signin {
        border-right: 0;
        margin-right: 0; 
        border-bottom: 1px solid #c6c6c6;
        padding-bottom: 10px;
    }
}

这非常适合让我的高清屏幕完全按照我的需要显示纵向视图。接下来,景观视图!这当然是我走向死胡同的地方。我还没有弄清楚一个对我有用的查询,到目前为止研究还没有就此进行任何讨论。有关如何为Landscape HD / Retina设备编写适当的媒体查询的任何想法吗?

到目前为止我尝试过的事情:

@media
only screen and (min-width; 1081px) and (-webkit-min-device-pixel-ratio: 1.25),
only screen and (min-width; 1081px) and ( min--moz-device-pixel-ratio: 1.25),
only screen and (min-width; 1081px) and ( -o-min-device-pixel-ratio: 1.25/1),
only screen and (min-width; 1081px) and ( min-device-pixel-ratio: 1.25),
only screen and (min-width; 1081px) and ( min-resolution: 200dpi),
only screen and (min-width; 1081px) and ( min-resolution: 1.25dppx)
{
    #checkoutoptions {
        overflow: auto;
    }

    #signin {
        float: left;
        clear: both;
        width: 45%;
    }

    .registeroptions { 
        float: left;
        position: relative;
        width: 50%;
    }

    #checkoutoptions #signin {
        border-bottom: 0;
        padding-bottom: 0; 
        border-right: 1px solid #c6c6c6;
        margin-right: 10px;
    }
}

目前正在运作(可以使用更多测试):

/* Portrait View */
@media
only screen and (max-width: 360px) and (-webkit-min-device-pixel-ratio: 1.25),
only screen and (max-width: 360px) and ( min--moz-device-pixel-ratio: 1.25),
only screen and (max-width: 360px) and ( -o-min-device-pixel-ratio: 1.25/1),
only screen and (max-width: 360px) and ( min-device-pixel-ratio: 1.25),
only screen and (max-width: 360px) and ( min-resolution: 200dpi),
only screen and (max-width: 360px) and ( min-resolution: 1.25dppx)
{
    /* Styles */
}

/* Landscape View */
@media
only screen and (min-width: 361px) and (-webkit-min-device-pixel-ratio: 1.25),
only screen and (min-width: 361px) and ( min--moz-device-pixel-ratio: 1.25),
only screen and (min-width: 361px) and ( -o-min-device-pixel-ratio: 1.25/1),
only screen and (min-width: 361px) and ( min-device-pixel-ratio: 1.25),
only screen and (min-width: 361px) and ( min-resolution: 200dpi),
only screen and (min-width: 361px) and ( min-resolution: 1.25dppx)
{
    /* Styles */
}

1 个答案:

答案 0 :(得分:3)

您可以在媒体查询中使用orientation:landscape而不是min-width

@media
only screen and (orientation:landscape) and (-webkit-min-device-pixel-ratio: 1.25),
only screen and (orientation:landscape) and ( min--moz-device-pixel-ratio: 1.25),
only screen and (orientation:landscape) and ( -o-min-device-pixel-ratio: 1.25/1),
only screen and (orientation:landscape) and ( min-device-pixel-ratio: 1.25),
only screen and (orientation:landscape) and ( min-resolution: 200dpi),
only screen and (orientation:landscape) and ( min-resolution: 1.25dppx)
{