I know that 600px comes later in the CSS file which could be a reason
This is usually the reason, aside from unrelated authoring mistakes or, worse, browser bugs. Anything that is greater than or equal to 768px is, by necessity, also greater than or equal to 600px, so they both have to match.
See the following related questions for more information:
but surely only one should only be applied if the screen size is either 600 or 768?
That's not true; @media
rules are completely independent of one another. It doesn't make sense for @media
rules to be exclusive, in particular when you consider that media queries can consist of any combination of media features.
For example, what should happen in this case when the media is (width: 600px) and (height: 300px)
? (The correct behavior is that every rule is applied, with the last one taking precedence, because there is no other way for the UA to account for both width
and height
when evaluating the queries.)
@media {
body { background-color: white; }
}
@media (min-width: 600px) {
body { background-color: red; }
}
@media (min-width: 300px) and (max-height: 300px) {
body { background-color: yellow; }
}
@media (max-height: 600px) {
body { background-color: blue; }
}