Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anchor hash to the bottom of the page

Tags:

html

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.

like image 971
OJuice Avatar asked Jul 19 '14 04:07

OJuice


People also ask

How do you anchor a DIV to the bottom of the page?

Set the position of div at the bottom of its container can be done using bottom, and position property. Set position value to absolute and bottom value to zero to placed a div at the bottom of container.

How do I redirect to the bottom of the page?

An <a> tag can also be used to mark a section of a web page as a target for another link to jump to. For example, this link will jump to the bottom of this page. If the "name" and "id" attribute is used, the <a> tag is an anchor, but if the "href" attribute is used then it is a link.


1 Answers

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.

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

document.body.scrollIntoView(false);

Inline JavaScript solution

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

Separate JavaScript solution

HTML

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

JavaScript

document.getElementById("scroll-to-bottom").addEventListener("click", function () {
  document.body.scrollIntoView(false);
});
like image 97
Nick McCurdy Avatar answered Oct 22 '22 00:10

Nick McCurdy