I need to develop some html pages for iphone/android phones, but what is the difference between max-device-width
and max-width
? I need to use different css for different screen size.
@media all and (max-device-width: 400px)
@media all and (max-width: 400px)
What's the difference?
max-width
refers to the width of the viewport and can be used to target specific sizes or orientations in conjunction withmax-height
. Using multiplemax-width
(ormin-width
) conditions you could change the page styling as the browser is resized or the orientation changes on a device like an iPhone.max-device-width
refers to the viewport size of the device regardless of orientation, current scale or resizing. This will not change on a device so cannot be used to switch style sheets or CSS directives as the screen is rotated or resized.max-width
is the width of the target display area, e.g. the browsermax-device-width
is the width of the device's entire rendering area, i.e. the actual device screenSame goes for
max-height
andmax-device-height
naturally.the difference is that max-device-width is all screen's width and max-width means the space used by the browser to show the pages. But another important difference is the support of android browsers, in fact if u're going to use max-device-width this will work only in Opera, instead I'm sure that max-width will work for every kind of mobile browser (I had test it in Chrome, firefox and opera for ANDROID).
What do you think about using this style?
For all breakpoints which are mostly for "mobile device" I use
min(max)-device-width
and for breakpoints which are mostly for "desktop" usemin(max)-width
.There are a lot of "mobile devices" that badly calculate width.
Look at http://www.javascriptkit.com/dhtmltutors/cssmediaqueries2.shtml:
max-device-width will have constant values (probably two)
The max-width is the width of the target display area means the current size of browser.
Don't use device-width/height anymore.
device-width, device-height and device-aspect-ratio are deprecated in Media Queries Level 4: https://developer.mozilla.org/en-US/docs/Web/CSS/@media#Media_features
Just use width/height (without min/max) in combination with orientation & (min/max-)resolution to target specific devices. On mobile width/height should be the same as device-width/height.