简体   繁体   中英

Media Query with orientation landscape ignores max-width

I'm trying to implement a landscape mobile design for a website. While working on a version for iPhone SE & iPhone 12 I noticed the following:

I adjusted the top value in two breakpoints for one of my div classes:

@media (min-width: 844px), screen and (orientation: landscape) { 
    .search-wrapper {
        top: 150px;
    }
}

@media (max-width: 667px), screen and (orientation: landscape) { 
    .search-wrapper {
        top: 65px;
    }
}

For some reason when I test in Google Chrome with a width of 890px, the styles within max-width: 667px are applied. I don't understand why, shouldn't it only be detected if device width is less than or equal to 667px? It seems like currently it only detects orientation: landscape and applies the styles without looking at max-width. Can anyone see the problem?

Okay, I found the mistake:

@media (max-width: 667px), screen and (orientation: landscape) {}

There is a comma there, this means max-width: 667px OR orientation:landscape, so the browser will check them seperately.

Doing it like this it will work:

@media screen and (max-width: 667px) and (orientation: landscape) {}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM