简体   繁体   English

视口meta对元素宽度的确切影响是什么?

[英]What exactly the effect of the viewport meta on elements width?

I read a w3school tutorial about viewport meta tag, so they give 2 examples to explain the usage of the tag: 我阅读了有关视口元标记的w3school教程,因此他们提供了2个示例来解释标记的用法:

<meta name="viewport" content="width=device-width, initial-scale=1.0">

The first example one without it shows as expected, while the second example with the tag adjust the image width on smartphones making it 100% the viewport width, witch doesn't make sense to me. 没有标签的第一个示例显示了预期的效果,而带有标签的第二个示例在智能手机上调整了图像宽度,使其变为100%的视口宽度,对我来说这没有任何意义。 Why would setting the virtual width equal to the device width make that kind of adjustment, the image shouldn't normally fit the whole width in both cases as it's set width of 460px is smaller than my device width of more than 1000px and a wider virtual width. 为什么将虚拟宽度设置为等于设备宽度进行这种调整,两种情况下图像通常都不适合整个宽度,因为它的设置宽度为460px小于我的设备宽度大于1000px且较宽的虚拟宽度。

My second inquiry is about initial-scale=1, shouldn't that be the default value, what would be different if we didn't declare it. 我的第二个查询是关于initial-scale = 1,这不应该是默认值,如果不声明的话会有所不同。

Thank you for your attention. 感谢您的关注。

Look at the CSS for that page. 查看该页面的CSS。

 img { max-width: 100%; height: auto; } 

The max-width overrides the width. 最大宽度会覆盖宽度。

In addition to Quentin's answer, 除了昆汀的答案,

If you set the initial scale to "1.0" then the web page is displayed to match the resolution of the target density 1-to-1. 如果将初始比例设置为“ 1.0”,则会显示网页以与目标密度1比1的分辨率相匹配。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM