如何使用<a> tag

时间:2016-11-02 16:32:21

标签: html css

I am making a page on my website that is kind of like a mini wiki. By that I mean I am having a page of information. At the top, I want a table of contents, where you click a link and it scrolls down. I think this would be html, but it might be css.

I used to know how to do this, but I can't remember, nor can I seem to find how to do it anywhere.

So to sum the question up, I want to use an <a> tag in html to, when clicked, scroll to a spot on the page.

2 个答案:

答案 0 :(得分:1)

只要您提供与h1请求匹配的内容标题id或类似#,它就会滚动到该内容 - 无论它是否相同页面或不同的页面。下面的基本示例

链接:

<a href="#sectiontitle">Section Title</a>

内容:

<h1 id="sectiontitle">Section Title Content</h1>

答案 1 :(得分:1)

您可以使用锚点。在href前加#,它会滚动到页面上的元素,其值与id之后的#值相同。

例如:

<a href="#contact">Contact</a>

...会将您链接到此:

<h1 id="contact">Contact us</h1>

...在同一页面。