iPhone 5 landscape media queries not working

2019-04-09 08:20发布

问题:

I want to display my page for portrait and landscape iPhones in a different way.

On iPhone 4/4S devices everything works fine (portrait and landscape), but on iPhone 5/5s just the Portrait mode works fine (landscape shows the normal PC website).

Do you know what is wrong?

My queries look like that:

Portrait:

@media (max-width: 320px) {
...
}

Landscape:

@media (min-width: 321px) and (max-width: 568px) {
...
}

UPDATE

My queries look now like

@media (max-width: 320px) {
    ...
}

@media screen and (max-device-width: 568px) {
    ...
}

but the picture is the same. iPhone 4/4S (portrait/landscape) and iPhone 5/5s (portrait) works, iPhone 5/5s (landscape) works not...

回答1:

There are media queries for portrait and landscape:

@media screen and (orientation:portrait) { 
    … 
}

@media screen and (orientation:landscape) {
    …
}

If you specifically want to target iPhone, here is a great resource: LINK



回答2:

For iPhone 5S landscape the media query wil be -

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

For any other smartphone whose device width you don't know, you can check and get the device width from - http://www.mydevice.io/ This may be helpful in making media queries targeting the smartphones of smaller companies like micromax, lava, etc