javascript jQuery Mobile 页面宽度太宽...
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6885633/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery Mobile page width is too wide...
提问by Travis
I am working on creating pages for mobile devices with jQuery Mobile.
我正在使用 jQuery Mobile 为移动设备创建页面。
Here is the basic page template I am using:
这是我正在使用的基本页面模板:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Test Page</title>
<link rel="stylesheet"
href="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.css" />
<script src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.js">
</script>
</head>
<body>
<div data-role="page">
<div data-role="header" data-theme="b">
<h1>Page Title</h1>
</div>
<div data-role="content">
<div data-role="content" data-theme="a">
Page Content
</div>
</div>
</div>
</body>
</html>
When I try to view this on a mobile phone (Samsung Galaxy, iPhone, etc.) the page width is far too large (forcing scrolling on small resolution devices or very small text on larger resolution devices.)
当我尝试在手机(三星 Galaxy、iPhone 等)上查看此内容时,页面宽度太大(在小分辨率设备上强制滚动或在较大分辨率设备上强制滚动非常小的文本。)
Can anyone tell me what I am doing wrong?
谁能告诉我我做错了什么?
Thank-you!
谢谢!
回答by Alex
try adding this in the head
尝试在头部添加这个
<head>
.....
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
</head>
also one <div data-role="content"> ... </div>
is enough
也一个<div data-role="content"> ... </div>
就够了
回答by Todd Parker
You need to add a meta viewport tag to your head to set the page width to device width. It's covered in the blog posts at jquerymobile and updated docs:
您需要在头部添加元视口标签以将页面宽度设置为设备宽度。它在 jquerymobile 的博客文章和更新的文档中有所介绍:
回答by andyb
I think the multiple data-role="content"
are causing a styling issue. The Anatomy of a Pagedoes not use multiple contentdata-role
and the boiler platetemplate does not either.
我认为多个data-role="content"
导致样式问题。该页面的剖析不使用多个内容data-role
和锅炉板模板不任。
回答by Jason Gennaro
This might have something to do with <div data-role="content">
.
这可能与<div data-role="content">
.
Not sure you can have two of those on a page.
不确定你可以在一个页面上有两个。
<div data-role="content">
<div data-role="content" data-theme="a">
Page Content
</div>
</div>
The docs don't suggest there could be more than one: http://jquerymobile.com/demos/1.0b1/#/demos/1.0b1/docs/pages/docs-pages.html
文档不建议可能有多个:http: //jquerymobile.com/demos/1.0b1/#/demos/1.0b1/docs/pages/docs-pages.html
回答by Misguided
It probably has something to do with your CSS. Check your <body>
's width and height.
它可能与您的 CSS 有关。检查您<body>
的 的宽度和高度。
For best results, you should use CSS media queries and check for screen resolution, thus having a different style depending on the user's screen.
为了获得最佳结果,您应该使用 CSS 媒体查询并检查屏幕分辨率,从而根据用户的屏幕使用不同的样式。
For further reading:
进一步阅读: