简体   繁体   English

同一页面中的 HTML 锚点不起作用

[英]HTML Anchor Points in Same Page Not Working

I'm relatively new to HTML so maybe there's been a really blatant solution I've been missing.我对 HTML 比较陌生,所以也许我一直缺少一个非常明显的解决方案。 But I'm making a single-scroll website (with bootstrap) with a very basic navbar for people to jump to the section they want.但是我正在制作一个带有非常基本的导航栏的单滚动网站(带有引导程序),供人们跳转到他们想要的部分。

The navbar is currently an ul with a background image that appears from the right on hover.导航栏目前是一个 ul,背景图像在悬停时从右侧出现。

I've followed various tutorials;我遵循了各种教程; created the anchor points and id tags, yet nothing seems to happen when I click on the navbar buttons.创建了锚点和 id 标签,但当我点击导航栏按钮时似乎没有任何反应。 And I feel like I'm missing a fairly obvious solution here.我觉得我在这里错过了一个相当明显的解决方案。 I've shifted the position of the anchors around, and tried a few variants in both html and css I found online but none seemed to have solved it for me.我已经改变了锚点的位置,并在网上找到的 html 和 css 中尝试了一些变体,但似乎没有一个为我解决了这个问题。 I've tried it on other browsers, so it isn't a browser issue.我已经在其他浏览器上试过了,所以这不是浏览器的问题。

Here's the navbar code:这是导航栏代码:

<div class="container-fluid menuholder">
    <div class="menu">
    <ul class="nobull menutext">
            <li><a href="#prologue menutext">Prologue<br><font weight="bold" color="white"><strong>The Beginning</strong></font></a></li>
            <li><a href="#chap1 menutext"><br>Chapter 1<br><font color="white"><strong>The Storyteller</strong></font></a></li>
            <li><a href="#chap2 menutext"><br>Chapter 2<br><font color="white"><strong>The Big Idea</strong></font></a></li>
            <li><a href="#epilogue menutext"><br>Epilogue<br><font color="white"><strong>It Begins</strong></font></a></li>
    </ul>
    </div>
</div>

and here's a relevant part of one of the sections it's supposed to automatically scroll to:这是它应该自动滚动到的部分之一的相关部分:

<div class = "container">
    <div class="row">
        <div class ="chap1title col-md-3" id="chap1">
            <h3>Chapter 1:</h3><br><h2>The Storyteller</h2>
        </div>
    </div>
</div>

Aaaand here's some images of the menu and an example of where I'd like the Chapter 1 button to scroll to Aaaand 这是菜单的一些图像以及我希望第 1 章按钮滚动到的示例

Frontpage首页

Navbar导航栏

Where I'd like it to scroll to我希望它滚动到的位置

Thank you so much in advance!非常感谢您!

It seems like, your link is not valid, you are adding menutext inside the href which should actually take the link or the id of the anchor element看起来,您的链接无效,您在 href 中添加了菜单文本,它实际上应该采用链接或锚元素的 id

<ul class="nobull menutext">
            <li><a href="#prologue">Prologue<br><font weight="bold" color="white"><strong>The Beginning</strong></font></a></li>
            <li><a href="#chap1"><br>Chapter 1<br><font color="white"><strong>The Storyteller</strong></font></a></li>
            <li><a href="#chap2"><br>Chapter 2<br><font color="white"><strong>The Big Idea</strong></font></a></li>
            <li><a href="#epilogue"><br>Epilogue<br><font color="white"><strong>It Begins</strong></font></a></li>
    </ul>

It seems like menu text is a class name, which should be added in the class似乎菜单文本是一个类名,应该在类中添加

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM