【发布时间】:2018-07-26 17:54:15
【问题描述】:
我正在尝试使用 Bootstrap 4 创建导航栏。 这是我的 package.json 文件的内容:
{
"name": "NAME here",
"version": "1.0.0",
"description": "Descripttion ges there",
"main": "index.html",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "author's name",
"license": "ISC",
"dependencies": {
"bootstrap": "^4.0.0",
"jquery": "^3.3.1",
"popper.js": "^1.12.9"
}
}
这里是页面index.html的代码
<!Doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<meta name="description" content="description here"/>
<meta name="author" content="author's name and contact" />
<link rel="stylesheet" href="./node_modules/bootstrap/dist/css/bootstrap.min.css" />
<title>Bienvenue a TSL Group</title>
</head>
<body>
<div class="container">
<div class="row">
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<a class="navbar-brand">Brand name</a>
</div>
<div class="navbar-collapse collapse navbar-right">
<ul class="nav navbar-nav">
<li>
<a href="">welcome</a>
</li>
<li>
<a href="">Products</a>
</li>
<li>
<a href=""> Services</a>
</li>
<li>
<a href="">Menu </a>
</li>
<li>
<a href="">Contact us</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
</body>
<script type="text/javascript" src="./node_modules/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="./node_modules/bootstrap/dist/js/bootstrap.min.js">
</script>
</html>
但不幸的是,当我在浏览器中运行页面时,导航栏没有显示。我不知道这段代码有什么问题。 有什么帮助吗?
【问题讨论】:
-
您的 JS/CSS 上是否收到任何控制台日志或 404 错误?
-
尝试将
navbar-default更改为navbar-light bg-light并检查您是否有其他必要的类。文档:getbootstrap.com/docs/4.0/components/navbar/#supported-content -
@Adam 没有。控制台很干净。没有显示错误
-
@Klooven 当我将 navbar-default 更改为 navbar-light bg-light 时,它只显示带有灰色背景色的品牌名称。但导航栏的其余部分不显示。
-
通过 WebDevBooster 检查答案。这应该对你有帮助。
标签: jquery bootstrap-4 navbar