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

FreeCodeCamp致敬页导航测试报错修复:保留汉堡菜单功能

Fix FreeCodeCamp Tribute Page Test 5 Warning While Keeping Hamburger Menu Functionality

I've run into this exact issue before! The problem is that FreeCodeCamp's test checks all elements with the .nav-link class inside the <nav> to ensure they link to a corresponding section on the page. Your hamburger menu link is just a trigger for JavaScript, not a navigation link, so it fails the test even though the functionality works fine.

Here are two simple solutions to fix this without breaking the hamburger menu:

This is the easiest fix. Since the hamburger button isn't meant to navigate to a page section, it doesn't need the .nav-link class. The test only checks links with that class, so removing it will make the warning disappear, and your menu toggle will still work:

<nav class="topnav" id="nav-bar">
  <a href="#header" class="active nav-link">Home</a>
  <a href="#img-div" class="nav-link">Image</a>
  <a href="#tribute-info" class="nav-link">info</a>
  <a href="#video" class="nav-link">video</a>
  <a href="#form" class="nav-link">contact</a>
  <a href="#footer" class="nav-link">footer</a>
  <!-- Remove .nav-link from this line -->
  <a href="javascript:void(0);" class="icon" onclick="myFunction()">
    <i class="fa fa-bars"></i>
  </a>
</nav>

Just make sure your CSS still styles the .icon class correctly (matching the other nav links if needed) so it looks consistent.

If you want to keep the .nav-link class for styling purposes, you can create a hidden dummy element on the page and point the hamburger's href to it, then prevent the default jump behavior:

  1. Add a hidden div somewhere in your HTML (like right after the <nav>):
<div id="menu-trigger" style="display: none;"></div>
  1. Update the hamburger link to use this ID and prevent default navigation:
<a href="#menu-trigger" class="icon nav-link" onclick="myFunction(); event.preventDefault();">
  <i class="fa fa-bars"></i>
</a>

The test will now detect that the href points to a valid element on the page, and event.preventDefault() stops the page from jumping to the hidden div. Your menu toggle functionality remains intact.

Either solution will resolve the test warning while keeping your hamburger menu working as expected. I recommend Solution 1 since it's cleaner and aligns with the purpose of the .nav-link class (for actual navigation links).

内容的提问来源于stack exchange,提问作者chesvoc

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 08:18:37