lat9:
I must respectfully disagree, the ordering does matter. Here's a couple of teeny testcases that illustrate.
First, with the maximum-width queries in descending width order, you'll see that a 360x640 screen displays white text on a red background and a 640x360 screen displays red text on a white background.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>A media query test</title>
<meta name="Keywords" content="" />
<meta name="Description" content="" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<meta name="robots" content="noindex, nofollow" />
<style type="text/css">
body {
background-color: blue;
color: green;
}
@media (max-width: 767px) {
body { background-color: white; color: red; }
}
@media (max-width: 480px) {
body { background-color: red; color: white; }
}
</style>
</head>
<body>
<div>What background color am I?</div>
</body>
</html>
```
> Now, reverse the order of the two maximum-width queries (so that they're in ascending order) and you'll see that there is no change in color/background-color between the 360x640 and 640x360 views. That's because the media-queries "cascade" down through the definition and since the query for the max:767 is later in the file, it takes precedence.
> ```
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>A media query test</title>
<meta name="Keywords" content="" />
<meta name="Description" content="" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<meta name="robots" content="noindex, nofollow" />
<style type="text/css">
body {
background-color: blue;
color: green;
}
@media (max-width: 480px) {
body { background-color: red; color: white; }
}
@media (max-width: 767px) {
body { background-color: white; color: red; }
}
</style>
</head>
<body>
<div>What background color am I?</div>
</body>
</html>
```
767 overlaps 480
Add a min-width so they don't overlap and the order of the media queries will not matter.
@media (min-width:481px) and (max-width: 767px) {
body { background-color: white; color: red; }
}