1

I have these <a href> buttons in index html and I want to open different pages but when I press the link I need to open the specific part of the second document which is an <article>.

I'm trying to develop an index.html where I have buttons with articles (like a blog) and when I click in the button it opens the document where the article is written for example technology.html each button goes to the specific article that I have written in that section, not loading from top the document.

Pointy
  • 405,095
  • 59
  • 585
  • 614
Mauro Stancato
  • 537
  • 1
  • 9
  • 19

2 Answers2

4

Set the id attribute on the element you’d like to link to, and include that ID at the end of your URL path, denoted by a #.

So, to link to <article id=“blog1”> on www.example.com, your anchor tag would be:

<a href=“http://www.example.com#blog1”>Link</a>
brads3290
  • 1,926
  • 1
  • 14
  • 20
1

What about this:-

If you want link's which redirect or target to current page element's then use targeting type URL's e.g. href="#element_to_target" and Here is a working example of your question.

article{ height: 500px; width: 100%; display: flex; align-items: center; justify-content: center; }
article p{ font-weigth: bold; }
#first{ background: red; color: #fff; }
#second{ background: blue; color: #fff; }
#third{ background: green; color: #fff; }
.fixed{ position: fixed; top: 3px; }
.fixed a{ background: #dcdcdc; padding: 10px; border: 1px solid #666; }
 <html style="scroll-behavior: smooth;">
  <div class="fixed">
    <a href="#first">First</a>
    <a href="#second">second</a>
    <a href="#third">third</a>
  </div>
  <article id="first"><p>Hi I'm first</p></article>
  <article id="second"><p>Hi I'm second</p></article>
  <article id="third">Hi I'm third</p></article>
</html>

If this is not working for you then add your URL before #_type_identifier e.g. href="http://yourdomain.or/path#element".

Hope this will helpful for you, thank you.

Amaan warsi
  • 184
  • 4
  • 18