We need to reorder the media queries, because if you write two rules “max-width: 320px” and “max-width: 375px” for one screen size which satisfy both the rules, it will choose the last css rule that was declared. You can use !important to the first rule which can solve your problem without reordering, but this not a correct approach of doing it.
As per your example, if the browser window is 320px pixels wide, the background-color will be green, because 320px condition satisfies both media queries, so it will select the last rule
//First rule
@media only screen and (max-width: 320px) {
.p {
background-color: red;
font-size: 30px;
}
}
//Last rule
@media only screen and (max-width: 375px) {
.p {
background-color: green;
font-size: 20px;
}
}
When you reorder, the background color will be green, when the screen size is 320px, because we have added the 320px media query at last.
//First rule
@media only screen and (max-width: 375px) {
.p {
background-color: green;
font-size: 20px;
}
}
//Last rule
@media only screen and (max-width: 320px) {
.p {
background-color: red;
font-size: 30px;
}
}
I hope this solves your query.