【问题标题】:Bootstrap font scaling too small on mobile移动设备上的引导字体缩放太小
【发布时间】:2015-03-01 01:25:44
【问题描述】:

我花了很多时间在 Foundation 上工作,而在 Bootstrap 上工作的时间却很少。我在 Bootstrap 中遇到了一个我不理解的响应问题,因为这似乎在 Foundation 中有效。问题是,虽然网格响应按预期工作,但我的字体变得非常小,以至于在移动设备上几乎难以辨认。请注意,在下面的示例中,我将字体大小设置为 14 像素,但在移动设备上它变得非常小。您可以通过单击 Chrome 开发工具中的移动按钮来查看此信息。

重现这个的html很简单,这里有个jsbin:http://jsbin.com/lumepumufu/1/

这是html:

<html>
  <head>
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
  </head>
  <body style="font-size:14px">
    <div class="container">
      <div class="row">
        <div class="col-lg-4">col-lg-4</div>
        <div class="col-lg-4">col-lg-4</div>
        <div class="col-lg-4">col-lg-4</div>
      </div>
    </div>
  </body>
</html>

【问题讨论】:

  • 你处于怪癖模式。
  • 你有没有像&lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;这样的head标签内的视口元标签?
  • @thebjorn 我直接在手机上查看该网站得到了相同的结果。
  • @ckuijjer 我对此进行了试验,但无论哪种方式都看到了相同的结果。我链接的 jsbin 没有那个。如果您在移动设备上查看该 jsbin,您是否看到相同的内容(小字体)?
  • 试试Bootlinting你的页面。

标签: html css twitter-bootstrap


【解决方案1】:

用“rem”代替px; (像素); 像 .myclass { font-size: 1rem; }

【讨论】:

    【解决方案2】:

    我遇到了小字体和小导航栏的问题,我的问题是在 css 中设置导航栏宽度,使用 max-width 而不是宽度解决了我的缩放问题

    【讨论】:

      【解决方案3】:

      如果你正在运行一个 Rails 应用程序,你可以试试 gem rails_layout

      【讨论】:

        【解决方案4】:

        Bootstrap 首先是移动设备。移动优先样式可以在整个库中找到,而不是在单独的文件中。

        为确保正确渲染和触摸缩放,请将视口元标记添加到您的头部

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

        【讨论】:

          【解决方案5】:

          您应该始终从模板开始,例如“基本模板”(http://getbootstrap.com/getting-started/#template)。这按预期工作:

          <!DOCTYPE html>
          <html lang="en">
            <head>
              <meta charset="utf-8">
              <meta http-equiv="X-UA-Compatible" content="IE=edge">
              <meta name="viewport" content="width=device-width, initial-scale=1">
              <title>Bootstrap 101 Template</title>
          
              <!-- Bootstrap -->
                  <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
          
              <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
              <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
              <!--[if lt IE 9]>
                <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
                <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
              <![endif]-->
            </head>
            <body style="font-size:14px">
              <div class="container">
                <div class="row">
                  <div class="col-lg-4">col-lg-4</div>
                  <div class="col-lg-4">col-lg-4</div>
                  <div class="col-lg-4">col-lg-4</div>
                </div>
              </div>
              <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
              <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
              <!-- Include all compiled plugins (below), or include individual files as needed -->
              <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
            </body>
          </html>
          

          这可能看起来很“笨拙”,但一切都是有原因的。

          【讨论】:

          • 正如@ziaprog 所说,关键是&lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
          • 一切都不存在是有原因的。这是一个 CSS 问题,无需为此目的包含 jquery 或 bootstrap javascript。如 cmets 和以下答案中所述,&lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt; 是正确答案。
          • 在开始使用 Bootstrap 的人的情况下,就像这个问题中的情况一样,我仍然觉得正确的方法是从提供的模板开始。随着您对内部工作原理的深入了解,您自然会根据项目的特定需求调整脚手架,但这是开始学习 Bootstrap 的一种非常令人沮丧的方式。
          猜你喜欢
          • 2014-08-05
          • 2012-07-26
          • 2015-11-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-10-09
          • 2015-12-13
          • 2016-06-04
          相关资源
          最近更新 更多