Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML HTML Links Anchors

Shams Nelson
Shams Nelson
2,888 Points

How can I get a link to the same page to scroll to the content

When something like <a href="#bottom_content"> is used to link to a div at the bottom of the same page, how can I have that page scroll to that location instead of teleport (for lack of a better word) there?

4 Answers

Kevin Korte
Kevin Korte
28,149 Points

You need Javascript to do this.

I have never used, nor did I know much about this plugin, but it came up first on a google search, so use at your own risk.

https://github.com/cferdinandi/smooth-scroll#readme

Ana Cristina Patiño Aguirre
Ana Cristina Patiño Aguirre
4,644 Points

Ok, If I have understood correctly, try addeding an id to the div and use the id's name as value to the href attribute like this

 <a href="#nameofthediv">Link to the div</a>

<div id="nameofthediv">Content</div>
Kevin Korte
Kevin Korte
28,149 Points

As I understood it, it sounds like he already has that working, because he asked how to make the page scroll there, instead of just jump right to that div, as this basic set up would.

Shams Nelson
Shams Nelson
2,888 Points

Perfect, thanks!

And sorry bout the confusion :)

Shams Nelson
Shams Nelson
2,888 Points

Just used this and it works great. Very simple and clean to set up as well. Thanks again.

~Shams