【发布时间】:2012-02-02 20:40:39
【问题描述】:
我试图弄清楚如何利用移动视口元标记自动缩放 HTML 页面的内容以适应 Web 视图。
约束:
- HTML 可能有也可能没有固定大小的元素(例如 img 的固定宽度为 640)。换句话说,我不想强制内容流动并使用 %'s。
- 我不知道 webview 的大小,我只知道它的纵横比
例如,如果我有一个图像 (640x100px),我希望图像在 webview 为 300x250 时缩小(缩小以适应)。另一方面,如果 webview 是 1280x200,我希望图像放大并填充 webview(放大以适应)。
在阅读了视口上的android docs 和iOS docs 之后,这似乎很简单:因为我知道我的内容的宽度(640),所以我只需将视口宽度设置为 640,然后让 webview 决定它是否需要缩放内容向上或向下以适合 web 视图。
如果我将以下内容放入我的 android/iPhone 浏览器或 320x50 网络视图中,则图像不会缩小以适应宽度。我可以左右滚动图像..
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test Viewport</title>
<meta name="viewport" content="width=640" />
<style type="text/css">
html, body {
margin: 0;
padding: 0;
vertical-align: top;
}
h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,cite,code,del,dfn,em,img,q,s,samp,small,strike,strong,sub,sup,tt,var,dd,dl,dt,li,ol,ul,fieldset,form,label,legend,button,table,caption,tbody,tfoot,thead,tr,th,td
{
margin: 0;
padding: 0;
border: 0;
font-weight: normal;
font-style: normal;
font-size: 100%;
line-height: 1;
font-family: inherit;
vertical-align: top;
}
</style>
</head>
<body>
<img src="http://www.dmacktyres.com/img/head_car_tyres.jpg">
</body>
</html>
我在这里做错了什么?视口元标记是否仅放大
【问题讨论】:
-
你有解决办法吗?
-
还没有。我猜不可能有简单的解决方案
标签: android iphone ios mobile viewport