Bootstrap 4的新功能,我正在尝试使用以下标记构建响应式导航栏:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>Test Website</title>
<link rel="stylesheet" href="/styles/style.css">
</head>
<body>
<!-- Navigation Bar -->
<nav class="navbar navbar-expand-md navbar-dark bg-primary sticky-top">
<a class="navbar-brand" href="tel:8005551212">Call Us At (800) 555-1212 For An Appointment</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="navResponsive">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item active"><a class="nav-link" href="#">Home</a></li>
<li class="nav-item"><a class="nav-link" href="#">Page 1 Test</a></li>
<li class="nav-item"><a class="nav-link" href="#">Page 2 Test</a></li>
<li class="nav-item"><a class="nav-link" href="#">Page 3 Test</a></li>
<li class="nav-item"><a class="nav-link" href="#">Page 4 Test</a></li>
<li class="nav-item"><a class="nav-link" href="#">Page 5 Test</a></li>
<li class="nav-item"><a class="nav-link" href="#">Page 6 Test</a></li>
</ul>
</div>
</nav>
<!-- End Navigation Bar -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
</body>
</html>
我遇到的问题是菜单文本包装的浏览器大小调整。有没有办法避免这种情况?
此外,如果单击切换菜单,则不会显示下拉列表。我错过了什么吗?
答案 0 :(得分:0)
data-target
你需要它#
以便将切换分配到菜单并且你分配了ID,它必须是
data-target="#navResponsive"
对于文本换行问题,您只需进行max-width
.navbar .navbar-brand {
max-width: 80%;
white-space: normal;
}
.navbar .navbar-brand {
max-width: 80%;
white-space: normal;
}
&#13;
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>Test Website</title>
<link rel="stylesheet" href="/styles/style.css">
<!-- Navigation Bar -->
<nav class="navbar navbar-expand-md navbar-dark bg-primary sticky-top">
<a class="navbar-brand" href="tel:8005551212">Call Us At (800) 555-1212 For An Appointment</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navResponsive">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item active"><a class="nav-link" href="#">Home</a></li>
<li class="nav-item"><a class="nav-link" href="#">Page 1 Test</a></li>
<li class="nav-item"><a class="nav-link" href="#">Page 2 Test</a></li>
<li class="nav-item"><a class="nav-link" href="#">Page 3 Test</a></li>
<li class="nav-item"><a class="nav-link" href="#">Page 4 Test</a></li>
<li class="nav-item"><a class="nav-link" href="#">Page 5 Test</a></li>
<li class="nav-item"><a class="nav-link" href="#">Page 6 Test</a></li>
</ul>
</div>
</nav>
<!-- End Navigation Bar -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
&#13;