移动网络的 max-device-width 和 max-width 有什么区别?

发布于 2024-11-25 04:33:28 字数 246 浏览 1 评论 0原文

我需要为 iphone/android 手机开发一些 html 页面,但是 max-device-widthmax-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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

魂归处 2024-12-02 04:33:28

max-width 是目标显示区域的宽度,例如浏览器

max-device-width 是设备整个渲染区域的宽度,即与实际设备屏幕

相同自然地适用于 max-heightmax-device-height

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

Same goes for max-height and max-device-height naturally.

雨落□心尘 2024-12-02 04:33:28

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 with max-height. Using multiple max-width (or min-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.

对不⑦ 2024-12-02 04:33:28

您认为使用这种样式怎么样?

对于主要用于“移动设备”的所有断点,我使用 min(max)-device-width 以及对于主要用于“移动设备”的断点对于“桌面”,使用min(max)-width

有很多“移动设备”无法很好地计算宽度。

看看 http://www.javascriptkit.com/dhtmltutors/cssmediaqueries2.shtml

/* #### Mobile Phones Portrait #### */
@media screen and (max-device-width: 480px) and (orientation: portrait){
  /* some CSS here */
}

/* #### Mobile Phones Landscape #### */
@media screen and (max-device-width: 640px) and (orientation: landscape){
  /* some CSS here */
}

/* #### Mobile Phones Portrait or Landscape #### */
@media screen and (max-device-width: 640px){
  /* some CSS here */
}

/* #### iPhone 4+ Portrait or Landscape #### */
@media screen and (max-device-width: 480px) and (-webkit-min-device-pixel-ratio: 2){
  /* some CSS here */
}

/* #### Tablets Portrait or Landscape #### */
@media screen and (min-device-width: 768px) and (max-device-width: 1024px){
  /* some CSS here */
}

/* #### Desktops #### */
@media screen and (min-width: 1024px){
  /* some CSS here */
}

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" use min(max)-width.

There are a lot of "mobile devices" that badly calculate width.

Look at http://www.javascriptkit.com/dhtmltutors/cssmediaqueries2.shtml:

/* #### Mobile Phones Portrait #### */
@media screen and (max-device-width: 480px) and (orientation: portrait){
  /* some CSS here */
}

/* #### Mobile Phones Landscape #### */
@media screen and (max-device-width: 640px) and (orientation: landscape){
  /* some CSS here */
}

/* #### Mobile Phones Portrait or Landscape #### */
@media screen and (max-device-width: 640px){
  /* some CSS here */
}

/* #### iPhone 4+ Portrait or Landscape #### */
@media screen and (max-device-width: 480px) and (-webkit-min-device-pixel-ratio: 2){
  /* some CSS here */
}

/* #### Tablets Portrait or Landscape #### */
@media screen and (min-device-width: 768px) and (max-device-width: 1024px){
  /* some CSS here */
}

/* #### Desktops #### */
@media screen and (min-width: 1024px){
  /* some CSS here */
}
残月升风 2024-12-02 04:33:28

max-device-width 是设备渲染宽度

@media all and (max-device-width: 400px) {
    /* styles for devices with a maximum width of 400px and less
       Changes only on device orientation */
}

@media all and (max-width: 400px) {
    /* styles for target area with a maximum width of 400px and less
       Changes on device orientation , browser resize */
}

max-width 是目标显示区域的宽度,即浏览器的当前大小。

max-device-width is the device rendering width

@media all and (max-device-width: 400px) {
    /* styles for devices with a maximum width of 400px and less
       Changes only on device orientation */
}

@media all and (max-width: 400px) {
    /* styles for target area with a maximum width of 400px and less
       Changes on device orientation , browser resize */
}

The max-width is the width of the target display area means the current size of browser.

长不大的小祸害 2024-12-02 04:33:28

区别在于 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).

烙印 2024-12-02 04:33:28

ma​​x-width是目标显示区域的宽度,例如浏览器; ma​​x-device-width是设备整个渲染区域的宽度,即实际设备屏幕的宽度。

• 如果您使用ma​​x-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.

却一份温柔 2024-12-02 04:33:28

如果您正在制作跨平台应用程序(例如使用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.

許願樹丅啲祈禱 2024-12-02 04:33:28

不要再使用设备宽度/高度。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文