[英]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-width
和initial-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还提到,定义
width
和initial-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-width
和initial-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.