Bootstrap 5 "Nav-bar" 崩溃不起作用

Bootstrap 5 "Nav-bar" collapse does not work

基本代码:

<?php
session_start();
if ((!isset($_SESSION['valid']) == true)) {
    unset($_SESSION['valid']);
    header('location:index.php');
}
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Noticias sobre Vacina - Digital</title>
    <!-- Bootstrap-->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.0/css/bootstrap.min.css" integrity="sha512-F7WyTLiiiPqvu2pGumDR15med0MDkUIo5VTVyyfECR5DZmCnDhti9q5VID02ItWjq6fvDfMaBaDl2J3WdL1uxA==" crossorigin="anonymous" referrerpolicy="no-referrer" />  <link rel="stylesheet" href="css/styles.css">

</head>

<body>

    <div class="cover-container d-flex w-100 h-100 mx-auto flex-column">
        <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
            <div class="container">
                <a class="navbar-brand" href="#">Noticias sobre a vacina</a>
                <button class="navbar-toggler" type="button" data-toggle="collapse" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="collapse navbar-collapse">
                    <ul class="navbar-nav mr-auto">
                        <li class="nav-item active">
                            <a class="nav-link" href="home.php"><i class="fas fa-home"></i> Home <span class="sr-only">(current)</span></a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="cadastro_noticia.php"><i class="fas fa-clipboard-list"></i> Cadastro de noticia </a>
                        </li>
                        <li class="nav-item dropdown">
                    </ul>
                    <form class="form-inline my-2 my-md-0">
                        <a class="nav-link active" href="index.php"><i class="fas fa-sign-out-alt"></i>Sair</a>
                    </form>
                </div>
            </div>
        </nav>
        <div id="wrapper" class="toggled" style="margin-left: 5%; display: inline;">
            <div class="container-fluid" id="conteudo">
            </div>
        </div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.0/js/bootstrap.bundle.min.js" integrity="sha512-PqRelaJGXVuQ81N6wjUrRQelCDR7z8RvKGiR9SbSxKHPIt15eJDmIVv9EJgwq0XvgylszsjzvQ0+VyI2WtIshQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>  
    <!-- <script src="js/noticia.js"></script> -->

</body>

</html>

我试过重定向,使用其他 CDN 和其他因素,但没有任何效果,none 使折叠起作用。我需要一些帮助,因为我不知道为什么它不起作用。 谁能帮我解释下原因,不胜感激

您必须将 data-toggle 更改为 data-bs-toggle 并使用 data-bs-target 属性。在折叠中添加IDdiv。就这些了。

<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#collapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse" id="collapse">