You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:Bootstrap导航栏折叠按钮(三横线icon-bar)无法显示

Hey there! I totally get how frustrating it is when that hamburger menu icon doesn’t show up when you’re just starting out with Bootstrap. Let’s walk through the most common fixes step by step:

Common Fixes for Missing Bootstrap Collapse Menu Icon

1. Match Your Bootstrap Version’s Component Structure

Bootstrap changed the hamburger icon structure between versions—this is the #1 cause of the issue:

  • Bootstrap 3: The three-line icon uses <span class="icon-bar"></span>, and you need three of them inside a .navbar-toggle button:
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
  <span class="icon-bar"></span>
  <span class="icon-bar"></span>
  <span class="icon-bar"></span>                        
</button>
  • Bootstrap 4/5: icon-bar is replaced with navbar-toggler-icon, and the button uses updated data attributes:
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent">
  <span class="navbar-toggler-icon"></span>
</button>

Pro tip: Bootstrap 5 uses the data-bs-* prefix instead of data-*—don’t mix these up!

2. Verify Bootstrap CSS/JS Files Are Properly Loaded

  • If you’re using local files, double-check file paths: CSS goes in the <head>, and JS (plus Popper.js for Bootstrap 4/5) goes at the end of <body>:
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="path/to/bootstrap.min.css">

<!-- Bootstrap JS + Popper.js (Bootstrap 4/5) -->
<script src="path/to/popper.min.js"></script>
<script src="path/to/bootstrap.min.js"></script>
  • For CDN links, use valid, up-to-date URLs (Bootstrap 5 bundles Popper.js for you):
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>

3. Check for Custom CSS Conflicts

Sometimes your own styles can overwrite Bootstrap’s default icon styles:

  • Open your browser’s dev tools (F12), select the toggle button, and inspect the icon-bar or navbar-toggler-icon element. Look for properties like display: none, background-color matching the navbar background, or missing height/width.
  • Adjust your custom CSS to either increase specificity or remove conflicting rules.

4. Ensure Your Navbar Structure Is Valid

The collapsible menu content must be wrapped in a .collapse.navbar-collapse container, and the button’s data-target (or data-bs-target) must match the container’s id:

<!-- Bootstrap 3 Example -->
<div class="collapse navbar-collapse" id="myNavbar">
  <!-- Your menu links here -->
</div>

<!-- Bootstrap 5 Example -->
<div class="collapse navbar-collapse" id="navbarSupportedContent">
  <!-- Your menu links here -->
</div>

5. Don’t Skip Required Navbar Classes

Make sure your main navbar element has the base .navbar class, plus a theme class like .navbar-default (Bootstrap 3) or .navbar-light/.navbar-dark (Bootstrap 4/5)—these classes set the icon’s color to contrast with the navbar background.

If none of these fix the issue, share a snippet of your full navbar code, and we can dig deeper!

内容的提问来源于stack exchange,提问作者Mohammad Sohanur Rahman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 08:47:41