I\'m finding the concept of the (min-width/max-width) media query a bit confusing.
Naturally if I was to design a media query I would want to say (in pseudo-code)....
min-width
in media queries is not related to the min-width
property you set on elements, those are two different things.
In media queries min-width: X
is true if the viewport has a width greater or equal to X, effectively working as screen.width >= X
. Obviously max-width
would then be equal to screen.width <= X
To me it makes perfect sense, if you read @media screen and (max-width:420px)
as a screen with a maximum width of 420px, so anything from 0 to 420px
Here is a simple example, hopefully it helps..
Say we have a website with the following media queries:
/* #1- Large desktop */
@media (min-width: 980px) { ... }
/* #2- Portrait tablet to landscape and desktop */
@media (min-width: 768px) and (max-width: 979px) { ... }
/* #3- Landscape phone to portrait tablet */
@media (max-width: 767px) { ... }
/* #4- Landscape phones and down */
@media (max-width: 480px) { ... }
If the screen size of the browser is 1200px, query #1 will be satisfied, as the minimum width of the browser has to be 980px for this query to be displayed.
Lets say we resize the browser now, and bring it all the way down to 250px.. query #4 is satisfied as the MAX is 480px..
Here is a simple translation of the queries..
@media (min-width: 980px) { ... }
Display if screen is greater than or equal to 980px
@media (min-width: 768px) and (max-width: 979px) { ... }
Display if screen is greater than or equal to 768px and less than or equal to 978px
@media (max-width: 767px) { ... }
Display if screen is greater than 480px and less than or equal to 767px.
@media (max-width: 480px) { ... }
Display if screen is less than or equal to 480px
Using these queries, you will always have a result, as one query is always satisfied.
The confusion here is that there is both a min-width
CSS property and media query with the same name:
@media (min-width: 420px) {...} /* This is read-only and is set to screen size */
.element { min-width: 420px; ...} /* This is setting a property of the selected element */