I'm creating a single-page portfolio website. My nav bar is fixed position. When a link is clicked, it will scroll up/down to the corresponding div that it is linked to (as nav bars are wont to do). Is there a clean way to make it so that the colors of the link in the nav bar change when they're on their corresponding div?
Asked
Active
Viewed 332 times
2 Answers
0
I'm not sure about the exact purpose. But you can use a css styling for a:active, or you can use jQuery to apply styling based on the position.

SMillerNL
- 103
- 8
0
I can think of a solution using php
If you get the current url using $_SERVER; as you are on the same page you're url will look like: http://example.com/#divid
now you can explode the link and get the value of corresponding div. Then you need to run a php if statement on each menu item to check if that's div on the current view and change the css class to active (with you preferred style)
Hope that helps. Please post some code, if you try.
We may find solution together

iamshahid
- 469
- 1
- 3
- 9