简体   繁体   English

width =设备宽度是否与初始比例= 1一致?

[英]Is width=device-width redundant alongside initial-scale=1?

Researching viewport behaviour, I've hit a bit of a snag in understanding the meta viewport declaration. 研究视口行为,我在理解元视口声明时遇到了一些障碍。

I see width=device-width and initial-scale=1 used together a lot but, as far as I can tell, the latter implies the former. 我看到width=device-widthinitial-scale=1一起使用很多,但据我所知,后者暗示前者。

MDN also mentions that defining both a width and initial-scale=1 will result in the width acting as a minimum viewport width. MDN还提到,定义widthinitial-scale=1将导致宽度作为最小视口宽度。 If this is the case then is there any need to define the width as device-width ? 如果是这种情况,那么是否需要将宽度定义为device-width Surely the initial-scale can't be 1 with any layout viewport smaller than the device-width anyway. 当然,任何布局视口小于设备宽度的初始比例都不能为1。

Am I missing something or is defining the width as device-width redundant here? 我错过了什么或者将宽度定义为设备宽度冗余吗?

Thanks 谢谢

Using both width=device-width and initial-scale=1 ensure cross browser/device compatibility. 使用width=device-widthinitial-scale=1确保跨浏览器/设备兼容性。 For example, for iOS devices, initial-scale=1 is needed for your page to pick up on orientation change of the device as width=device-width will not. 例如,对于iOS设备,页面需要initial-scale=1来获取设备的方向更改,因为width=device-width不会。 Using both ensure maximum effectiveness using the meta viewport tag. 使用两者都可以使用元视口标记确保最大效果。

The 2 tags are not the same. 2个标签不一样。

The ' width=device ' tag tells the browser to use the device's real width as the 100% width of the screen. ' width=device '标签告诉浏览器将设备的实际宽度用作屏幕的100%宽度。 If you omit it, a mobile device will simulate as if it has higher resolution and your content will not be stretched to full width. 如果省略它,移动设备将模拟它具有更高的分辨率,并且您的内容不会被拉伸到全宽。

The initial-scale is the zoom level on first load. initial-scale是第一次加载时的缩放级别。 If it is set to 1, along with ' width=device ', then the content will not be zoomed out or in. You will also not be able to zoom out more than the initial scale (but you will still be able to zoom in). 如果它设置为1,同时设置为' width=device ',则内容将不会缩小或缩小。您也无法缩小超过初始比例(但您仍然可以放大)。 That will be as if you set 'minimum-scale' to 1 as well. 这就好像你将'minimum-scale'设置为1。

There is also a ' maximum-scale ' and if you set it to 1 as well, the user will not be able to zoom in more than the initial scale. 还有一个“ maximum-scale ”,如果你也设置为1,用户将无法放大超过初始比例。

This is an example of how you can create an 'app-like' feeling, where the content uses the device's width in a 1:1 ratio. 这是一个如何创建“类似app”的感觉的示例,其中内容以1:1的比例使用设备的宽度。

<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">

Hope this helps! 希望这可以帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 元视口:width = device-width或initial-scale = 1或两者 - Meta viewport : width=device-width or initial-scale=1 or both 视口宽度=设备宽度,初始比例= 1,没有给我全宽度 - Viewport width=device-width, initial-scale=1 not giving me full width <meta name=“viewport” content=“width=device-width, initial-scale=0” />不工作 - <meta name=“viewport” content=“width=device-width, initial-scale=0” /> not working 这个标签是什么(<meta name="“viewport”" content="“width=device-width," initial-scale="1”"> ) 做? - What does this tag (<meta name=“viewport” content=“width=device-width, initial-scale=1”>) do? HTML 页面上的表格比 div 使用更多的宽度<viewport "width=device-width initial-scale=1.0"> - Table on HTML page takes much more width than div with using <viewport "width=device-width initial-scale=1.0"> 使用视口width = device-width,initial-scale = 1,maximum-scale = 1不能使我的页面适合我的手机屏幕 - Using viewport width=device-width, initial-scale=1, maximum-scale=1 doesnt fit my page to my phone screen 元视口:不能将“ width = 640”与“ initial-scale = 1.0”一起使用吗? - meta viewport: can not use “width=640” with “initial-scale=1.0”? 覆盖设备宽度 - Override device-width 为什么“宽度=设备宽度”完全不起作用? - Why is "width=device-width" totally not working? 视口-iPad上的width = device-width - Viewport - width=device-width on iPad
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM