TXChetG
TXChetG

Reputation: 342

How to write media queries for HD/Retina Display in Landscape position?

Essentially I have two different styles I want enacted on mobile devices. One set for Portrait View, the other for Landscape. I have run into a problem during testing in that my Galaxy S4 is showing what is supposed to be my Landscape View while in Portrait View due to it's large resolution. I had my initial CSS written as below.

#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;
    }
}

With some research I found that there are media queries available for HD/Retina screens. So I added the following:

@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;
    }
}

This worked great for getting my HD screen to show the Portrait View exactly as I wanted. Next up, Landscape View! This is of course where I've hit a dead end. I have yet to figure out a query that will work for me, and research isn't turning up any discussion on this so far. Any thoughts out there on how to write a proper media query for Landscape HD/Retina devices?

Things I've tried so far:

@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;
    }
}

Currently it's working (could use more testing):

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

Upvotes: 1

Views: 4851

Answers (1)

boz
boz

Reputation: 4908

You could use orientation:landscape in your media query instead of 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)
{

Upvotes: 4

Related Questions