Kumakaja Kumakaja - 11 days ago 6
CSS Question

Unable to create an anchor for the h1 tag

I have an h1 tag:

<h1 id="something">
My header
</h1>


I wonder, why doesn't it work as anchor? When I go to "localhost:3000/#something", it doesn't scroll down the page to the point where the h1 is located.

Answer

It works. Posibly your h1 is not low enough to trigger scroll or i just found out that the problem is in your localhost:3000/#something, it should be localhost:3000#something instead Please try this one

function go() {
  window.location += "#something";
  alert(window.location);
}
div {
  border: 1px solid green;
  height: 100vh;
  width: 100%;
}
<div>
  <button onclick="go()">scroll</button>
</div>
<h1 id="something">
  My header
</h1>

Comments