无法在移动/ipad浏览器上浮动twitter引导导航条



使用"navbar"one_answers"navbar-fixed-top"类可以在向下滚动页面时将导航条浮动在页面顶部。这似乎不适用于手机/ipad浏览器。我们为什么以及如何让它们在移动浏览器上浮动。在ipad(safari, chrome) Android(firefox) Windows Phone(IE)上试过了。

<!DOCTYPE HTML>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="http://code.jquery.com/jquery.min.js"></script>
    <script type="text/javascript" src="http://twitter.github.com/bootstrap/assets/js/bootstrap.js"></script>
    <link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet">
    <link href="http://twitter.github.com/bootstrap/assets/css/bootstrap-responsive.css" rel="stylesheet">
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
  <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
       <span class="icon-bar"></span>
       <span class="icon-bar"></span>
       <span class="icon-bar"></span>
  </a>
  <span class="brand"><img title="Logo" alt="Logo" src="static/images/iu_logo.gif" /></span>
  <div class="nav-collapse">
  <ul class="nav">
    <li class="active">
        <a id="homeLink" href="#">Home</a>
    </li>
    <li class="dropdown">
      <a class="dropdown-toggle" id="newsLink" href="#">News</a>
      <ul class="dropdown-menu">
        <li><a href="#">Link 1</a></li>
        <li><a href="#">Link 2</a></li>
        <li class="divider"></li>
        <li><a href="#">Another link</a></li>
      </ul>
    </li>
  </ul>
  <ul class="nav pull-right">
    <li id="loginLink"><a href="#" id="loginButton">Login</a></li>
  </ul>
  </div>
</div>
</div>
50 lines of text (just to have the page scrollable)
</body>
</html>

我确实在头部标签中有下面的行来启用移动设备的引导响应。

<meta name="viewport" content="width=device-width, initial-scale=1.0">
任何建议

我也遇到了同样的问题,我在其他框架上做了一些调查。由于JQuery移动工作正确固定导航条的问题必须只在Bootstrap的一边,事实上他们故意禁用它(更多细节见下文)。

你可以尝试添加inline样式。

<div class="navbar navbar-fixed-top navbar-inverse" style="position:fixed">

当然你需要相应地调整导航栏样式。我做了如下操作:

/* Override Bootstrap Responsive CSS fixed navbar */
@media (max-width: 979px) {
  .navbar-fixed-top,
  .navbar-fixed-bottom {
      position: fixed;
      margin-left: 0px;
      margin-right: 0px;
  }
}

我在响应式css之后添加了这个。

我尝试了各种设备…低价的安卓平板电脑,高端的安卓手机。我从未尝试过iOS。最神奇的是它非常流畅在Firefox for Android上。

这是Bootstrap的作者在github上回答的问题之一,并参考了JQM采用的详细解决方案:https://github.com/twitter/bootstrap/issues/1617

引导不要在小屏幕上使用固定导航条,因为它在移动设备上不能很好地工作。在bootstrap-responsive.css中可以找到:

@media (max-width: 979px) {
  ...
  .navbar-fixed-top,
  .navbar-fixed-bottom {
    position: static;
  }
  ...
}

尝试删除它或只是不加载bootstrap-responsive.css样式表,并检查将在移动设备上发生什么,然后你会看到这是必要的:)在我的低成本Android移动固定元素不固定在滚动期间。遍历所有可见屏幕。滚动结束后,浏览器重新计算固定元素的位置,导航条跳转到正确的位置。

最新更新