当您向下滚动页面时,使用“navbar”和“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>
我在head标签中有以下行,以便为移动设备启用bootstrap响应.
<Meta name="viewport" content="width=device-width,initial-scale=1.0">
有什么建议
解决方法
我遇到了同样的问题,我对其他框架进行了一些调查.
由于JQuery Mobile在固定导航栏上正常工作,问题必须只在Bootstrap’侧,实际上他们是故意禁用它(下面有更多细节).
由于JQuery Mobile在固定导航栏上正常工作,问题必须只在Bootstrap’侧,实际上他们是故意禁用它(下面有更多细节).
您可以通过添加内联样式来尝试.
<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之后添加了这个.
我试过各种各样的设备…一个低成本的Android平板电脑,我的高端Android手机.
我从没试过iOS.
最令人惊奇的是它在Firefox for Android上非常流畅.
这是关于github的问题之一,由Bootstrap的作者回复,引用了JQM采用的详细解决方案:https://github.com/twitter/bootstrap/issues/1617