HTML simple anchor link doesn't work in Chrome/Firefox

倾然丶 夕夏残阳落幕 提交于 2019-12-11 11:16:06

问题


I'm making a portfolio page here (http://198.96.94.51/v2/) and while clicking on the navigationMenu links on the side really fast, they don't seem to redirect to the proper anchor (some of them don't move the page at all). I've initialized my anchor tags like this

<ol class="curtains">
    <li id="home" class="cover">
        <a id="home"></a>
        <header data-fade="550" data-slow-scroll="3">
            <h1>John Smith</h1>
            <h2>HOBBY/JOB TITLE</h2>
        </header>
    </li>
</ol>

My navbar code -

<ul id="navigationMenu">
    <li>
        <a class="home" href="#home">
            <span>Home</span>
        </a>
    </li>
    <li>
        <a class="about" href="#about">
            <span>About</span>
        </a>
    </li>
    <li>
         <a class="projects" href="#projects">
            <span>Projects</span>
         </a>
    </li>
    <li>
        <a class="resume" href="#resume">
            <span>Resume</span>
        </a>
    </li>
    <li>
        <a class="contact" href="#contact">
            <span>Contact us</span>
        </a>
    </li>
</ul>

But just clicking on the navbar, or even typing #home into the address bar won't bring the browser back to the top sometimes. Is there anything I'm doing wrong?


回答1:


Ids identify anchor points so they must be unique.

But if you just want to go to the top of the page you should try a simple # as value for your href attribute.

A link to the id of e.g. a <div> tag would lead you to this <div> tag.

<a href="#anchor"></a>

<div id="anchor"></div>

this fiddle shows you: http://jsfiddle.net/aYGFR/1/




回答2:


You can give like this: <a id="home" href="home.php">Home</a>



来源:https://stackoverflow.com/questions/17938762/html-simple-anchor-link-doesnt-work-in-chrome-firefox

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!