我没有控制" navbar-fixed-top"的宽度。使用Bootstrap" col - "类。建议我到目前为止建议添加Bootstrap CSS或使用' container-fluid'虽然我还没有弄清楚如何使用" col- 来控制宽度 - "在后一种选择。
基本上,我想对下面的脚本做同样的事情,但导航栏固定在顶部。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Case</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="col-md-2"></div>
<div class="col-md-8">
<nav class="navbar navbar-inverse">
<div class="navbar-header">
<a class="navbar-brand" href="#">WebSiteName</a>
</div>
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Page 1</a></li>
<li><a href="#">Page 2</a></li>
<li><a href="#">Page 3</a></li>
</ul>
</nav>
<p>1. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll.</p>
<p>2. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll.</p>
<p>3. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll.</p>
<p>4. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll.</p>
</div>
<div class="col-md-2"></div>
</body>
</html>
我已使用this W3Schools page on navbar-fixed-top来测试上面的HTML。你有什么工作想法吗?
答案 0 :(得分:0)
您可以在CSS中设置固定导航栏的宽度,并以自动边距为中心。
SELECT articlecode, description, retailprice, sellingprice
FROM article
WHERE retailprice - sellingprice = 150
答案 1 :(得分:0)
将position:fixed
(如navbar-fixed-top
)添加到从正常页面流中删除的任何元素后,它将无法在Bootstrap col-*
内完成。< / p>
最好只设置宽度并将导航栏与页面内容分开..
.navbar-fixed-top {
width:66.66%; /* same as width of col-md-8 */
margin:0 auto;
}
这是一个有效的演示: http://codeply.com/go/ogg6K1uhGU
您将看到使用媒体查询,以便导航栏在较小的屏幕上保持响应。
答案 2 :(得分:0)
我到目前为止使用的解决方案是使用Bootstrap CSS中的.container。请参阅下面的脚本。到目前为止,我注意到的唯一缺陷是浏览器调整大小的各个阶段中导航栏和内容宽度的像素宽差异。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Case</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- start of css overwriting container, add 'container-overwrite' to <nav class> !-->
<style>
@media (min-width: 768px) {
.container-overwrite{
width:96.3%;
}}
@media (min-width: 992px) {
.container-overwrite{
width:63.7%;
}}
@media (min-width: 1200px) {
.container-overwrite{
width:64.7%;
}}
body {
padding-top: 70px;
}
</style>
<!-- end of css !-->
</head>
<body>
<div class="col-md-2"></div>
<div class="col-md-8">
<div class="container">
<nav class="navbar navbar-inverse navbar-fixed-top container container-overwrite">
<div class="navbar-header">
<a class="navbar-brand" href="#">WebSiteName</a>
</div>
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Page 1</a></li>
<li><a href="#">Page 2</a></li>
<li><a href="#">Page 3</a></li>
</ul>
</nav>
</div>
<p>1. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll.</p>
<p>2. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll.</p>
<p>3. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll.</p>
<p>4. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll.</p>
</div>
<div class="col-md-2"></div>
</body>
</html>
答案 3 :(得分:0)
解决方案是在您的代码中添加 <div class="container-fluid">
:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Case</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="col-md-2"></div>
<div class="col-md-8">
<div class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">WebSiteName</a>
</div>
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Page 1</a></li>
<li><a href="#">Page 2</a></li>
<li><a href="#">Page 3</a></li>
</ul>
</div>
</div>
<p>1. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll.</p>
<p>2. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll.</p>
<p>3. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll.</p>
<p>4. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll. A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll.</p>
</div>
<div class="col-md-2"></div>
</body>
</html>