如何让 html 页面自动适合移动设备屏幕?

How can I make an html page automatically fit mobile device screens?

我正在使用 <iframe> 在 html 页面上放置一个 Formidable Form,但我希望它在移动设备上全屏显示。到目前为止,我正在使用以下代码:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <style>
  @import url(http://fonts.googleapis.com/css?family=Londrina+Sketch);

  body {
  background-color: #f3eedd;
  width: 750px;
  overflow:scroll;
    overflow-x:hidden;
  }

h2 {
    font-size: 20px;
    color: #c13e18;
    margin: 10px 30px 10px 30px;
}

</style>
</head>
<body>
<div id="header">
<h2>Book Supheroes Unite</h2>
</div>
<div id="form">
<iframe src="http://challenge-the-box.com/wp-admin/admin-ajax.php?action=frm_forms_preview&form=sbyrt02
" frameborder="0" scrolling="no" style="width:280px;height:535px;"></iframe></div>
</html>

我认为这与视口有关?但是,我对此并不完全确定!

你可以使用media queries! 看起来像这样:

@media (max-width: 640px) {
  //your css to make it full screen
}
<meta name="viewport" content="width=device-width, initial-scale=1.0">

此元标记允许您定位移动设备并将宽度设置为屏幕大小。

提供的文件here!

同时考虑迁移到 bootstrap 响应式网页设计的 CSS 框架! Twitter Bootstrap

就我个人而言,我会使用像 bootstrap 这样的库来实现将类似的东西添加到你的头脑中。

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

Bootstrap 允许您使用您的内容创建动态网格,而不管设备大小。您只需在更大的容器内创建 div,例如流体容器:

<div class="container-fluid">
<div class="row">
    ...
  </div>
</div>