This particular project involves a website that consolidates all its pages/sections into one page. Each section has been assigned a unique ID (such as section1, section2, section3, etc.) and these IDs have also been linked to the top navigation href's, for example
<a href="#section2">About Us</a>
. Upon clicking on "About Us" in the top navigation, you will be directed to the corresponding div with the ID of #section2
.
While I've managed to get this part working correctly, I'm encountering a few issues - despite my research efforts, I haven't been able to pinpoint the exact keywords needed to find solutions! Therefore, I haven't found anything useful yet and any assistance would be greatly appreciated.
The problems I'm facing are:
- When clicking a button from the menu, it jumps to the specified section but not to the very top of that section - instead, it scrolls down about 100px. Why does this happen?
- Is there a way to enable smooth scrolling without the abrupt jump?
- How can I easily apply the class .active to buttons when they are clicked and scrolled to their respective sections?
You can find the code snippet here: http://jsfiddle.net/nd8MN/3/, which includes both the HTML and CSS used.
[The rest of the HTML and CSS code snippets follow...]