搜索

首页  >  问答  >  正文

为什么下拉菜单项不显示?

我的导航栏使用 Bootstrap 5。问题是用户图标的下拉项(登录)未显示。这是我的代码:

<button class="btn dropdown-toggle" type="button" id="userDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                <i class="fa-solid fa-user text-white fs-5"></i>
            </button>
            <div class="dropdown-menu dropdown-menu-right" aria-labelledby="userDropdown">
                <a class="dropdown-item" href="#">Login</a>
            </div>

P粉304704653P粉304704653464 天前618

全部回复(1)我来回复

  • P粉546257913

    P粉5462579132023-09-13 14:05:48

    对于 Boostrap 5,您需要 data-bs-toggle="dropdown" 而不是 data-toggle

    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
        
    <button class="btn dropdown-toggle" type="button" id="userDropdown" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
        <i class="fa-solid fa-user text-white fs-5"></i>
    </button>            
                
    <div class="dropdown-menu dropdown-menu-right" aria-labelledby="userDropdown">
        <a class="dropdown-item" href="#">Login</a>
    </div> 

    回复
    0
  • 取消回复