关于视口的问题
我已经在网上浏览了很多关于视口的资源(在 apple.com、quirksmode.org 上),但仍然有点困惑......
假设我有一个宽度为 400 px 的页面......现在我想优化iPad 观看也是如此。
如果我将元视口设置为设备宽度(我认为这意味着 iPad 在任何方向上都是 768px);
- 这是否意味着我的字体大小会放大为 768px ?或者
- 我的页面会缩小,就好像它的宽度是 768 像素而不是 400 像素?
我不太清楚如果我们在不同的场景下使用viewport会产生什么效果?
在任何页面上使用视口是否有任何负面影响(如果页面宽度<或>设置的视口宽度)
有人可以以一种易于理解的方式帮助我..
谢谢。
I have gone through a lot of resources online for viewport (on apple.com, quirksmode.org), but am still confused slightly....
Say I have a page which has a width of 400 px..Now I want to optimize the same for iPad viewing..
If I set the meta viewport as device-width (which I think would mean 768px for iPad in any orientation);
- Would that mean that my font-size would scale up for 768px ? OR
- My page would get scaled down as if it were a 768 px width and not 400px ?
I am not really clear as to what the effect is if we use viewport for different scenarios?
Is there any negative effect of using viewport on any page (if page width < or > the set viewport width)
Could someone please help me in an easy to understand way..
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我衷心推荐阅读这篇文章: http://www.quirksmode.org/mobile/viewports2.html< /a>
它可能会回答您有关视口的部分或全部问题。这当然对我有帮助。
关键是要理解视觉视口(浏览器的像素宽度)和布局视口(CSS 想要以像素为单位渲染站点的宽度)之间的区别。显然,在大多数情况下,布局视口将比视觉视口大得多。
例如,您的网站可能有 950 像素宽,但浏览器的视觉视口可能只有 320 像素。通常移动浏览器会向右缩小以显示整个页面,但谁能读懂呢?
因此,在标记中设置
将布局视口设置为 320px - 与视觉视口相同!
I heartily recommend reading this article: http://www.quirksmode.org/mobile/viewports2.html
It may answer some or all of your question about the viewport. It certainly helped me.
The key is in understanding the difference between the visual viewport (the browser's pixel width) and the layout viewport (the width that your CSS wants to render the site in pixels). Clearly in most cases the layout viewport will be much bigger than the visual viewport.
E.g. your website may be 950px wide but the browser's visual viewport may only be 320px. Ordinarily mobile browsers zoom right out to be able to display the entire page but who the hell can read that ?
So setting
<meta name="viewport" content="width=320" ... >
in your markup sets the layout viewport to be 320px - the same as the visual viewport !好的,为了消除对媒体查询的困惑,您需要了解使用媒体查询的概念。
它检查浏览器的视口并将内部CSS代码强加给浏览器。您将在视图端口范围的不同媒体查询中设置不同的 CSS。代码将在 css 文件中为:
还有另一种方法。根据媒体查询添加不同的 CSS 文件,如下所示:
因此,根据这些查询,您可以为相同的输出设置不同的样式。现在,如果您想施加实际上不在浏览器中的不同视口大小,那么您必须设置元标记。
这意味着,浏览器设置了它的视口,并会根据实际的浏览器视口大小按需缩小或放大。它仅适用于“Opera Mobile 11”及更高版本。因此,如果您的浏览器视口为 360 且元设置为 320,则它将按比例放大或放大 1.125 倍。
Ok, to remove the confusion on media query you need to know the concept of using media query.
it checks the view port of the browser and impose the inner css code to browser. you will set different css in different media query on view port range. code will be in css file as:
There also have another way. adding different css file based on media query as below:
So, according to these query you can set different style for the same output. Now if you want to impose a different view port size which are not actually in browser, then you have to set the meta tag.
It means, the browser set its view port and will scale down or scale up as needed according to the actual browser view port size. And it works only on "Opera Mobile 11" onward. So if your browser's view port is 360 and meta set to 320 then it will be scaled up or zoomed in by a factor of 1.125.
根据我的理解(我对所有媒体查询和一起使用视口有点困惑),如果你将视口设置为 480px 并且 iPad 更大,那么它看起来就像在台式电脑上一样。它会忽略这一点,因为它对于 ipad 来说并不是那么小的视口。
除非您专门为 iPad 创建一个名为 (ipad.css) 的特定文件,并为该宽度和该宽度之间的设备添加单独的媒体查询。例如。
或使用媒体查询
您还可以重置设备的CSS,以便它知道将字体大小、类标记名调整回移动设备应有的样子。
希望有帮助。
以下是我一直在使用的一些资源:
From my understanding (I'm a bit confused myself with all the media queries and using viewport together), if you make the viewport 480px and the iPad is larger then that it's going to look like how it does on your desktop computer. It will ignore this because it's not that small of a viewport for the ipad.
Unless you make a specific file just for the iPad called (ipad.css) and add a separate media queries for devices between this and that width. eg.
or use media queries
You can also reset you css for devices so it knows to resize fonts, classes tagnames back to how they should be for mobile devices.
Hope that helps.
Here are some resources I've been playing with: