How can I use the function href="#"?

Asked

Viewed 699 times

-1

I’m making a website, and I wanted to make sure that when someone clicks on a button it doesn’t go to the beginning of the page but to the middle of the page and, or the end page.

Explaining betterLink(Please see this link), when someone clicks on the "home" they would go to the blue part, which is the top of the page, and when they click on the "About" they would go to the yellow part.

  • Good morning. This is not a function, but a shortcut. Visit https://pt.wikipedia.org/wiki/Brasil. When you hover your mouse over the history index, you will see the following link https://pt.wikipedia.org/wiki/Brasil#Hist%C3%B3ria in the lower left corner of your computer. If you click on it, the scroll will automatically move up to the requested index. That’s it. You can of course use this type of Javascript event tagging, but then it’s another matter. You can learn Javascript by accessing: https://www.w3schools.com/js/default.asp

3 answers

2

href="#pularpara" and your div with id related to href id="pularpara"

<a href="#pularpara">clique aqui para pular...</a>
<div style="height:5000px">Nada</div>
<h1 id="pularpara">Para Pular</h1>

  • can I do it? <H1> <id="About the game"> About the game</H1>

  • I changed the example to from div to H1, you can not use in this way described.

1

Using anchors:

<a href="#topo">Topo</a>
<a href="#meio">Meio</a>
<a href="#fim">Fim</a>

<div id="topo">Div Topo</div>
<div id="meio">Div Meio</div>
<div id="fim">Div Fim</div>

Note that the href are respectively the id of each div, thus, when you click on <a href="fim"> the page will be rolled until the top of the <div id="fim"> stay at the top of the browser window.

0

Use anchors to solve this problem, it’s quite simple.

<a href="#div1">Link 1</a>
<a href="#div2">Link 2</a>

<div id="div1" style="width:200px;height:400px;background-color:red"></div>
<div id="div2" style="width:200px;height:400px;background-color:blue"></div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.