I have the below html document with a Navbar. The problem when navbar is collapsed, I can't get the content to display. I have made sure that data-target is pointing to the right element. Also I have tried to download a navbar code directly from Bootstrap's home page, and when I collapse the navbar I can't see the content either. Therefore I suspect if the problem could be related to my Bootstrap installation?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap css-->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href=/static/main.css>
<link rel="stylesheet" href=/static/style.css>
<link rel="shortcut icon" type="image/png" href="/static/media/favicon.png"/>
<title>Dimsum Siblings</title>
<!--font-awesome including icon for shopping cart-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<nav id ="navbar">
<a href="/" id="navbarLogoLink">
<img src="static/media/logoWithText.png" alt="" id="navbarLogo">
</a>
<button type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="#navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span ></span>
</button>
<div id="navbarNav">
<ul >
<li id="navbarListItem">
<a id ="mainNavlink" href=""><h3 id="linkText">ABOUT US</h3></a>
</li>
<li id="navbarListItem">
<a id ="mainNavlink" href="/dimsumshop"><h3 id="linkText">ORDER DIMSUM BOX</h3></a>
</li>
<li id="navbarListItem">
<a id ="mainNavlink" href=""><h3 id="linkText">INSTRUCTIONS</h3></a>
</li>
<li id="navbarListItem">
<a id ="mainNavlink" href=""><h3 id="linkText">CONTACT</h3></a>
</li>
</ul>
</div>
</nav>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg OMhuP IlRH9sENBO0LRn5q 8nbTov4 1p" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj 3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
</body>
</html>
The css part
#navbarLogo {
width: 10rem;
height: auto;
}
.navbar-brand img {
height: 50px;
width: auto;
padding-left: 30px;
}
#linkText {
font-family: hdFontMedium;
font-size: 1.5rem;
font-weight: bold;
text-align: center;
}
#navbarNav {
justify-content: flex-end;
align-items: center;
}
#navbarListItem {
padding-left: 10px;
padding-right: 10px;
}
CodePudding user response:
Here you go...
Change:
data-toggle="collapse"
(Bootstrap 4) todata-bs-toggle="collapse"
(Bootstrap 5)data-target="#navbarNav"
(Bootstrap 4) todata-bs-target="#navbarNav"
(Bootstrap 5)
#navbarLogo {
width: 10rem;
height: auto;
}
.navbar-brand img {
height: 50px;
width: auto;
padding-left: 30px;
}
#linkText {
font-family: hdFontMedium;
font-size: 1.5rem;
font-weight: bold;
text-align: center;
}
#navbarNav {
justify-content: flex-end;
align-items: center;
}
#navbarListItem {
padding-left: 10px;
padding-right: 10px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap css-->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href=/static/main.css>
<link rel="stylesheet" href=/static/style.css>
<link rel="shortcut icon" type="image/png" href="/static/media/favicon.png" />
<title>Dimsum Siblings</title>
<!--font-awesome including icon for shopping cart-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<nav id="navbar">
<a href="/" id="navbarLogoLink">
<img src="static/media/logoWithText.png" alt="" id="navbarLogo">
</a>
<button type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="#navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span ></span>
</button>
<div id="navbarNav">
<ul >
<li id="navbarListItem">
<a id="mainNavlink" href="">
<h3 id="linkText">ABOUT US</h3>
</a>
</li>
<li id="navbarListItem">
<a id="mainNavlink" href="/dimsumshop">
<h3 id="linkText">ORDER DIMSUM BOX</h3>
</a>
</li>
<li id="navbarListItem">
<a id="mainNavlink" href="">
<h3 id="linkText">INSTRUCTIONS</h3>
</a>
</li>
<li id="navbarListItem">
<a id="mainNavlink" href="">
<h3 id="linkText">CONTACT</h3>
</a>
</li>
</ul>
</div>
</nav>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg OMhuP IlRH9sENBO0LRn5q 8nbTov4 1p" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj 3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
</body>
</html>