手机浏览网站时如何自动缩小?
就我而言,我将 div 宽度设置为 500px
,
但在手机中浏览时它会自动缩小。
到底是如何实现的,它是特定于设备的吗?
In my case I made the div width 500px
,
but it automatically zoomed out when browsed in a mobilephone
How's the magic done exactly,is it device specific?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能想在 html 页面的头部尝试类似的操作:
有关更多信息,请参见此处:
http://davidbcalhoun.com/2010/viewport-metatag
You might want to try something like this in the head of the html page:
For more info see here:
http://davidbcalhoun.com/2010/viewport-metatag
编辑:下面的答案不再反映当前的正常做法。现在有一个相当完善的标准,称为元视口,它控制页面在移动设备上的缩放方式。如果没有这一点,网站将被视为“不适合移动设备”,并且移动浏览器会以典型的桌面宽度显示页面,然后缩小以显示全宽度。
这是特定于浏览器的。
它甚至是大多数移动浏览器(例如 Android、诺基亚 S60、Opera Mini)中的可配置选项。我更喜欢将其关闭,以便页面以正常的 100% 缩放打开(如果它被切断,我只需滚动)。
有些人喜欢立即看到整个页面宽度,即使文本太小而无法阅读,然后双击即可放大。
浏览器通常首先计算页面的总宽度。在此计算中,任何灵活宽度元素都被视为可以容纳其所有子元素的最小宽度。如果它小于或等于浏览器窗口的宽度,则不会进行缩放,但如果它更大,浏览器会将其设置为虚拟页面宽度,并且如果用户打开此选项,则会缩小所有内容(例如缩小)在现代桌面浏览器中),以便页面的最小宽度占据浏览器窗口的宽度。
Edit: the answer below no longer reflects current normal practice. There is now a fairly well established standard called the meta viewport which controls how the page is scaled on mobile. In the absence of this, sites are deemed "not mobile friendly" and mobile browsers show the page at typical desktop width, zoomed out to show full width.
It is browser specific.
It's even a configurable option in most mobile browsers (eg Android, Nokia S60, Opera Mini). I prefer to have it turned off, so that pages open with normal 100% zoom (and if it's cut off, I just scroll).
Some people prefer to see the whole page width at once even if the text is too small to read, then double-tap to zoom up after that.
The browser typically calculates the total width of the page first. In this calculation any flexible-width element is taken to be the minimum width which can fit all its children. If this is less or equal to the width of the browser window no scaling is done, but if it's greater, the browser sets this as the virtual page width and, if the user has turned this option on, scales everything down (like zooming out in a modern desktop browser) so that that minimum width of the page occupies the width of the browser window.
浏览器会做它想做的事。由于移动电话的屏幕较小,因此浏览器可能会缩小以使页面看起来更舒适。
The browser do whatever it wants to. Since mobile phones have a small screen probably this browser zoomed out to be more pleasant to look the page.