I've been struggling to figure out the context of this issue, but I'll do my best!
Currently, I am working on a webpage where I have set the navigation bar's position
to fixed
so that it stays visible while scrolling. The href
attributes of the links in the navigation bar are set to specific IDs on the page, allowing users to navigate by clicking on these links. However, when clicking on the link that takes you to the top of the page, the content gets hidden behind the navigation bar. I thought about defining new "coordinates" for the page to reposition its elements:
The HTML markup for the navigation bar:
<nav id="navbar">
<ul id="navItems">
<li><a id="wel">Welcome</a></li>
<li><a id="SendMsg">Send me a message</a></li>
<li><a id="myResume">My Resume</a></li>
</ul>
</nav>
The HTML markup for the first content section:
<div class="Mask1"></div>
<div id="intro">
<div id="name">
<h1 id="moh">Mohamed Ahmed Eshawaf
</h1>
</div>
<br />
<div id="pos">
<h3>.NET Developer</h3>
</div>
<br />
<div id="pos2">
<h3>Web Designer</h3>
</div>
<br />
<div id="pos3">
<p style="font-size:24pt">
Some paragraph here!
</p>
</div>
</div>
CSS styles:
#navbar {
background-color: #019AA4;
border-bottom-left-radius: 50px;
border-bottom-right-radius: 50px;
margin: 0 auto;
width: 1000px;
height: 50px;
position: fixed;
right: 13%;
top: 0px;
z-index: 888;
display: block;
}
ul#navItems li {
float: left;
line-height: 48px;
margin-right: 30px;
}
#navItems {
position: absolute;
top: 0px;
right: 150px;
list-style-type: none;
width: 615px;
height: 50px;
margin: 0 auto;
}
I have used jQuery code like this to smoothly scroll through the page:
$("#wel").click(function () {
$('html, body').animate({
scrollTop: $(".Mask1").offset().top
}, 2000);
In my latest attempt, I added a div
with the ID "mask" and set its width to 50px. By linking to this virtual element instead of the original content, I hoped to address the issue.
.Mask1
{
width:50px;
}
If there is any confusion, please let me know. My problem is that, upon clicking the Welcome link in the navigation bar, the name element (with the ID moh) gets hidden behind it. I would like to position it directly beneath the navbar. *Feel free to suggest any improvements to how I've framed the question.