html - 导航链接工作但未通过 FreeCodeCamp 挑战中的测试 : Product Landing Page

标签 html css

我刚刚开始使用 freecodecamp 学习编码。但是,我被困在“创建产品登陆页面”的挑战中。

挑战要求如下:

User Story #5: When I click a .nav-linkbutton in the nav element, I am >taken to the corresponding section of the landing page.

对我来说,我的代码似乎满足了这个要求(它似乎确实有效),但由于某种原因它没有通过测试。如果有任何建议,我将不胜感激:

这是相关代码(如果需要查看整个页面,请告诉我)。

<nav id="nav-bar" class="nav-bar">
<ul>
<li class="nav-link"><a href="#home">Home</>
<li class="nav-link"><a href="#about">About</a>
<li class="nav-link"><a href="#news">News</a>
</ul>
</nav>


<div id="home">
</div>
<div id="about">
<iframe id="video" width="560" height="315" src="https://www.youtube.com/embed/cta5-rpoeB4" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
<div id="news">
</div>

当我运行测试时,出现以下错误:

  1. When I click a .nav-link button in the nav element, I am taken to the corresponding section of the landing page.' Each .nav-link element should have an href attribute : expected false to >equal true AssertionError: Each .nav-link element should have an href attribute : >expected false to equal true

非常感谢您的帮助。

最佳答案

看起来您点击的是 anchor (a) 元素,而不是 li 元素。您可以尝试为标签提供 nav-link 类吗?

他们在这里特别提到按钮的另一件事。你没有任何元素。如果您创建一个带有 .nav-link 和 href 属性的按钮,它会起作用吗?

关于html - 导航链接工作但未通过 FreeCodeCamp 挑战中的测试 : Product Landing Page,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57997118/

相关文章:

javascript - 图像翻转

jQuery 动画边框似乎不起作用

css - 为 CSS 选择器创建 Sublime Text 3 片段

javascript - 如何在一个元素出现在屏幕上后立即更改它的 css 属性

html - html标签上的 Angular 输入和原生html属性有什么区别

html - 如何在不添加文本的情况下使 div 背景可见

html - 带 Bootstrap 的行流体内的行流体

jquery - 相对于容器的响应式固定位置元素

html - 在台式计算机上尝试匹配引导卡高度

javascript - .removeClass() 只工作一次