Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

bootstrap 5 - Why href doesn't work inside nav-item in boostrap 5?? I can't navigate to the relative path play.html on another page

Here is my navbar and I want when I click Play Hangman to redirect to another page in this case (play.html), but the link doesn't work! Do I need some attribute or something else?

<nav class="navbar navbar-expand-sm navbar-dark bg-dark fixed-top" id="main-nav">
  <div class="container">
    <a class="navbar-brand" href="#home">
      <img src="./img/logo.png" alt="logo" width="30" height="30">
      <h4 class="d-inline align-middle">Petrovski</h4>
    </a>
    <button class="navbar-toggler" type="button" id="toggler-btn" data-bs-toggle="collapse" data-bs-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon" id="close-navbar"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarCollapse">
      <ul class="navbar-nav ms-auto">
        <li class="nav-item">
          <a href="#home" class="nav-link">Home</a>
        </li>
        <li class="nav-item">
          <a href="#about" class="nav-link">About</a>
        </li>
        <li class="nav-item">
          <a href="#contact" class="nav-link">Contact</a>
        </li>
        <li class="nav-item">
          <a href="play.html" class="nav-link">Play Hangman</a>
        </li>
       </ul>
    </div>
  </div>
</nav>  
question from:https://stackoverflow.com/questions/65880137/why-href-doesnt-work-inside-nav-item-in-boostrap-5-i-cant-navigate-to-the-re

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I copied your code and it works just fine. The error must be somewhere else. I noticed that you are missing closing </ul tag. Check the rest of your code, maybe you have another unclosed tag, missing quotation mark, or something else that is interfering with the rest of your code. I would recommend using HTML validator, such as https://validator.w3.org/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...