Html 将哈希锚定到页面底部

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24836798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 02:16:59  来源:igfitidea点击:

Anchor hash to the bottom of the page

html

提问by OJuice

What is the universal HTML anchor tag to go to the 'bottom' of the page? I know the tag '#' automatically brings the user to the top of the page but I am not so sure about the bottom of the page though.

转到页面“底部”的通用 HTML 锚标记是什么?我知道标签“#”会自动将用户带到页面顶部,但我不太确定页面底部。

回答by elixenide

There isn't one.

没有一个。

You can simulate it, though, with something like <a id="bottom"></a>, then linking to #bottom.

不过,您可以使用类似 的内容模拟它<a id="bottom"></a>,然后链接到#bottom.

You might find this posthelpful, as well.

您可能会发现这篇文章也很有帮助。

回答by Nick McCurdy

In my opinion, it's better to implement this in JavaScript and definitely jump to the bottom of the page, instead of relying that the CSS styling on a link makes it always appear at the bottom of the page.

在我看来,最好在 JavaScript 中实现这一点并且肯定跳转到页面底部,而不是依赖于链接上的 CSS 样式使其始终出现在页面底部。

This JavaScript snippet will scroll to the bottom of the document:

此 JavaScript 代码段将滚动到文档底部:

document.body.scrollIntoView(false);

Inline JavaScript solution

内联 JavaScript 解决方案

<a href="javascript: document.body.scrollIntoView(false);">Scroll to bottom</a>

Separate JavaScript solution

单独的 JavaScript 解决方案

HTML

HTML

<a href="#" id="scroll-to-bottom">Scroll to bottom</a>

JavaScript

JavaScript

document.getElementById("scroll-to-bottom").addEventListener("click", function () {
  document.body.scrollIntoView(false);
});

回答by Ed Heal

bung <a name="end"></a>at the end and then <a href="#end">for the link

<a name="end"></a>在最后,然后<a href="#end">是链接

回答by Bronson Thomas Senior

tag #footer

标签#footer

and then

进而

id the footer like so...

像这样识别页脚...

<a href="#footer">Go to bottom</a>

<footer id="footer"></footer>

in contrast you can tag to top of page without anchor using the # symbol only. You can use #top as well

相比之下,您可以仅使用 # 符号在没有锚点的情况下标记到页面顶部。你也可以使用#top

Like so...

像这样...

<a href="#">Go to top</a>