2

I am trying to create a navbar using Bootstrap 4. Here is the content og my package.json file :

{
 "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"
  }
}

and here is the code of the page 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>

But unfortunately, when I run the page in the browser, the navbar is not displayed. I don't know what is wrong with this code. Any help?

WebDevBooster
  • 14,674
  • 9
  • 66
  • 70
the smart life
  • 305
  • 8
  • 26
  • Are you getting any console logs or 404 errors on your JS/CSS? – Adam Feb 15 '18 at 21:14
  • Try changing `navbar-default` to `navbar-light bg-light` and check that you have other necessary classes. Docs: https://getbootstrap.com/docs/4.0/components/navbar/#supported-content – Klooven Feb 15 '18 at 21:15
  • @Adam No. The console is clean. No errors displayed – the smart life Feb 15 '18 at 21:16
  • @Klooven when i change navbar-default to navbar-light bg-light, it only display the brand name with a gray background color. But the rest of the navbar is not displayed. – the smart life Feb 15 '18 at 21:19
  • Check the answer by WebDevBooster. That should help you. – Klooven Feb 15 '18 at 21:21
  • If safari browser not showing Navbar of bootstrap 4: then try this https://stackoverflow.com/a/65234112/7186739 – Billu Dec 10 '20 at 12:02

1 Answers1

3

It's not showing because the Bootstrap 4 classes and structure are different from Bootstrap 3.

Also important:

When loading JavaScript files, you must load jQuery first, then Popper.js and then Bootstrap.js.

This is what a Bootstrap 4 navbar looks like:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<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>

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link</a>
      </li>
      <li class="nav-item dropdown">
        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          Dropdown
        </a>
        <div class="dropdown-menu" aria-labelledby="navbarDropdown">
          <a class="dropdown-item" href="#">Action</a>
          <a class="dropdown-item" href="#">Another action</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="#">Something else here</a>
        </div>
      </li>
      <li class="nav-item">
        <a class="nav-link disabled" href="#">Disabled</a>
      </li>
    </ul>
    <form class="form-inline my-2 my-lg-0">
      <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
    </form>
  </div>
</nav>
WebDevBooster
  • 14,674
  • 9
  • 66
  • 70