移动网络的 max-device-width 和 max-width 有什么区别?
我需要为 iphone/android 手机开发一些 html 页面,但是 max-device-width
和 max-width
之间有什么区别?我需要针对不同的屏幕尺寸使用不同的CSS。
@media all and (max-device-width: 400px)
@media all and (max-width: 400px)
有什么区别?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
max-width
是目标显示区域的宽度,例如浏览器max-device-width
是设备整个渲染区域的宽度,即与实际设备屏幕相同自然地适用于
max-height
和max-device-height
。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.max-width
是指视口的宽度,可与max-height
结合使用来定位特定尺寸或方向。使用多个max-width
(或min-width
)条件,您可以在调整浏览器大小或在 iPhone 等设备上更改方向时更改页面样式。max-device-width
指的是设备的视口大小,无论方向、当前比例或调整大小如何。这不会在设备上发生变化,因此不能用于在屏幕旋转或调整大小时切换样式表或 CSS 指令。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.您认为使用这种样式怎么样?
对于主要用于“移动设备”的所有断点,我使用
min(max)-device-width
以及对于主要用于“移动设备”的断点对于“桌面”,使用min(max)-width
。有很多“移动设备”无法很好地计算宽度。
看看 http://www.javascriptkit.com/dhtmltutors/cssmediaqueries2.shtml:
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 是设备渲染宽度
max-width 是目标显示区域的宽度,即浏览器的当前大小。
max-device-width is the device rendering width
The max-width is the width of the target display area means the current size of browser.
区别在于 max-device-width 是整个屏幕的宽度,而 max-width 是指浏览器显示页面所使用的空间。但另一个重要的区别是 Android 浏览器的支持,事实上,如果你要使用 max-device-width ,这只适用于 Opera,相反,我确信 max-width 适用于各种移动浏览器(我已经在 Chrome、firefox 和 Opera for ANDROID 中测试过它)。
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).
max-width是目标显示区域的宽度,例如浏览器; max-device-width是设备整个渲染区域的宽度,即实际设备屏幕的宽度。
• 如果您使用max-device-width,当您更改桌面上浏览器窗口的大小时,CSS 样式不会更改为不同的媒体查询设置;
• 如果您使用最大宽度,当您更改桌面上浏览器的大小时,CSS 将更改为不同的媒体查询设置,并且您可能会看到移动设备的样式,例如作为触摸友好菜单。
max-width is the width of the target display area, e.g. the browser; max-device-width is the width of the device's entire rendering area, i.e. the actual device screen.
• If you are using the max-device-width, when you change the size of the browser window on your desktop, the CSS style won't change to different media query setting;
• If you are using the max-width, when you change the size of the browser on your desktop, the CSS will change to different media query setting and you might be shown with the styling for mobiles, such as touch-friendly menus.
如果您正在制作跨平台应用程序(例如使用phonegap/cordova),则
不要使用设备宽度或设备高度。而是在 CSS 媒体查询中使用宽度或高度,因为 Android 设备会出现设备宽度或设备高度问题。对于 iOS 来说,它工作得很好。仅 Android 设备不支持 device-width/device-height。
If you are making a cross-platform app (eg. using phonegap/cordova) then,
Don't use device-width or device-height. Rather use width or height in CSS media queries because Android device will give problems in device-width or device-height. For iOS it works fine. Only android devices doesn't support device-width/device-height.
不要再使用设备宽度/高度。
device-width、device-height 和 device-aspect-ratio 在媒体查询级别 4 中已弃用:
https://developer.mozilla.org/en-US/ docs/Web/CSS/@media#Media_features
只需将宽度/高度(没有最小/最大)与方向和方向结合使用即可。针对特定设备的(最小/最大)分辨率。移动设备上的宽度/高度应与设备宽度/高度相同。
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.