我的Bootstrap有问题。当我在codepen中检查我的代码时,导航栏是响应式的,从可见链接更改为汉堡菜单,但如果我在我的文档中检查它,它总是汉堡菜单,无论它的大小分辨率。你能帮助我吗?我试图解决它,我不知道发生了什么。
body {
background-image: url("img/bg.png");
font-family: 'Raleway', sans-serif;
}
<html lang="pl">
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
<link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.6/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<nav class="navbar navbar-toggleable-md navbar-light" id="commRollover">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="#"><img src="img/logo.png" alt="Logo" style="height: 40px;"></a>
<div class="collapse navbar-collapse justify-content-end" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">O nas<span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
</ul>
</div>
</nav>
</div>
</body>
答案 0 :(得分:3)
你需要使用&#34; navbar-expand-lg&#34;或&#34; navbar-expand-md&#34;等等,使bootstrap 4导航栏只在较小的屏幕上显示汉堡菜单。
这是官方的自助示例。
https://getbootstrap.com/docs/4.0/components/navbar/#supported-content
示例与您的代码合并。
<div class="container">
<nav class="navbar navbar-toggleable-md navbar-expand-md navbar-light" id="commRollover">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="#"><img src="img/logo.png" alt="Logo" style="height: 40px;" ></a>
<div class="collapse navbar-collapse justify-content-end" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">O nas<span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
</ul>
</div>
</nav>
</div>