HTML: 如何在页面中使用内部链接到文本?
HTML: How to use internal links to text in a page?
将 link 放入文本非常简单:<a href=www.link.com> Text </a>
,将 link 制作成图片也是如此,但我想知道如何做,而且我有尚未通过多次 google 搜索找到答案,我如何在顶部有一个 table 内容,其中每个项目都是可点击的 link,使您在页面中进一步下降。如何将内部 link 用于同一页面上的文本?
我相信如果您创建一个 <div id="section1">Text </div>
并将 #section1 放入 URL 中,浏览器会将页面设置为该部分。
您可以在此处阅读更多内容https://en.wikipedia.org/wiki/URI_fragment
很简单。您只需向想要 link 的任何元素添加一个 id 即可。例如,<h1 id="Hello"></h1>
。然后将您的 href
设置为 #
,然后将 ID <a href="#Hello">Go to Hello</a>
.
您可以在内容 table 中的 link 的 href 属性中给文本元素 ID,然后 link 给这些 ID,方法是在 ID 前加上前缀哈希符号。示例:
#tableofcontents {
background-color: #ccc;
}
<div id="tableofcontents">
<ul>
<li>
<a href="#ref1">Reference 1</a>
</li>
<li>
<a href="#ref2">Reference 2</a>
</li>
<li>
<a href="https://en.wikipedia.org/wiki/URI_fragment#Examples">You can even point the link to a specific element on another website</a>
</li>
</ul>
</div>
<p id="ref1">A paragraph with much text inside. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam
spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam
spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam
spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam
spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam
spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy.</p>
<p id="ref2">The second paragraph; it still has much content, but less than the previous one. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam
spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy.</p>
将 link 放入文本非常简单:<a href=www.link.com> Text </a>
,将 link 制作成图片也是如此,但我想知道如何做,而且我有尚未通过多次 google 搜索找到答案,我如何在顶部有一个 table 内容,其中每个项目都是可点击的 link,使您在页面中进一步下降。如何将内部 link 用于同一页面上的文本?
我相信如果您创建一个 <div id="section1">Text </div>
并将 #section1 放入 URL 中,浏览器会将页面设置为该部分。
您可以在此处阅读更多内容https://en.wikipedia.org/wiki/URI_fragment
很简单。您只需向想要 link 的任何元素添加一个 id 即可。例如,<h1 id="Hello"></h1>
。然后将您的 href
设置为 #
,然后将 ID <a href="#Hello">Go to Hello</a>
.
您可以在内容 table 中的 link 的 href 属性中给文本元素 ID,然后 link 给这些 ID,方法是在 ID 前加上前缀哈希符号。示例:
#tableofcontents {
background-color: #ccc;
}
<div id="tableofcontents">
<ul>
<li>
<a href="#ref1">Reference 1</a>
</li>
<li>
<a href="#ref2">Reference 2</a>
</li>
<li>
<a href="https://en.wikipedia.org/wiki/URI_fragment#Examples">You can even point the link to a specific element on another website</a>
</li>
</ul>
</div>
<p id="ref1">A paragraph with much text inside. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam
spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam
spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam
spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam
spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam
spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy.</p>
<p id="ref2">The second paragraph; it still has much content, but less than the previous one. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam
spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy. SPAM Spam spam spammy.</p>