I am currently encountering a tricky issue with hashed anchor links. Here is a simple representation of my HTML code :
<div class="main-wrap">
<header></header>
<aside>
<nav>
<ul>
<li><a href="#article1">Article1</a></li>
<li><a href="#article2">Article2</a></li>
<li><a href="#article3">Article3</a></li>
</ul>
</nav>
</aside>
<section>
<article id="article1">Content Here</article>
<article id="article2">Content Here</article>
<article id="article3">Content Here</article>
</section>
<footer></footer>
and the CSS :
body{overflow: scroll;}
.main-wrap{
overflow: hidden;
position: relative;
}
header{
position: relative;
z-index: 3;
height: 10vh;
}
aside{
position: fixed;
width: 22%;
height: 84vh; /* Equal to 100vh - (header + footer)vh */
top: 10vh;
left: 0;
bottom: 6vh;
}
section{
position: relative;
min-height: 84vh; /* Equal to 100vh - (header + footer)vh */
width: 78%;
left: 22%; /* Equal to aside width*/
}
footer{
position: relative;
z-index: 3;
height: 6vh;
}
I've created a sidebar menu with hashed links to have a scrolled navigation, wich as far as I've been is working. But when I'm clicking on the hashed anchors, all the elements are moving a little further top, including header and footer and are hidden by the overflow:hidden;
property of the .main-wrap
element. In addition when I go back to the non-hashed page, the issue is still running unless I reload it.
I can't find any clue of how I can fix it. Any ideas ?
Edited : I also use a reset.css that is setting the body
and html
padding and margin to 0.
Edited 2 :
I think I know what's going on. By clicking on an anchor-link the body is forced to scroll the .main-wrap
div and that's why everything looks like it has moved top. In fact the overflow:hidden;
property of .main-wrap
has just moved a little further down and is hiding the wrong parts.