When you use MIN-WIDTH
and MAX-WIDTH
it refers to the width of the browser you are currently using based on the resolution of the device, that is, the problem is generated because even smaller devices like an iphone for example have the same resolution as common monitors.
The best alternative is to use the DEVICE WIDTH
which refers to the width of the screen that the device appears to have (EX: 1024 of a 1024X768 screen) ie you do not work with resolutions, you work with screen sizes.
To make the media want to be based on this it is necessary to use the metatag VIEWPORT
that makes the resolution the same size as the screen of the device, or almost that. It makes the device use the width it appears to have and not its resolution.
More about the viewport here: Manipulating the Viewport
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
NOTE: You can modify your need by changing the value of the attributes:
width - Set a width for the viewport. Values can be in
PX or "device-width", which automatically determines a value equal to
device screen width.
height - Set a height for the viewport. Values can be in
PX or "device-height", which automatically determines a value equal to
height of device screen.
initial-Scale - Sets the viewport’s initial scale.
user-Scalable - Sets the possibility for the user to "zoom in"
a certain place of the screen. It is activated when the user hits two
times with your finger in a place on the screen.
With this, your code will be based on the width of the device. An iphone has a much smaller width than a 24-inch monitor", that is, it will not generate the problem since monitors will always be larger than mobile devices and the media querie will use its width as a base.
I consider this the most viable and recommended alternative, since devices with different screen sizes carry different CSS rules, IE, a mobile device will not display specific things for desktops and vice versa.
Another alternative is to work with device width directly in the media queries but this is a bit laborious since it should add max-device-width, min-device-width in each media querie.
EX:
@media only screen and (max-device-width: 1024px) { ...
Yes. Start working with device-width which is the width of the device or screen, not its resolution (max-width, min-width). Unless you have a legitimate reason to restrict style sheets based on the resolution and not the size of the display window, then just use min-width / max-width and avoid min-device-width / device-width max .
– user21847