Hi – While you are working this out, forget about the dynamic PHP part.
start with a single link, hard-wired to be active
<ul id="nav">
<li id="archives" class="active"><a href="https://localhost/wordpress/?page_id=2">archives</a></li>
`
I added just two lines of CSS – turned off your stylesheet and just worked with these two lines of CSS. I saw them displaying as intended on my setup, so I know they are correct
ul#nav li.active { background-color: red; }
ul#nav li.active a { color: yellow; }
Use my code exactly the way I listed it here.
When I added your CSS in, I didn’t see a thing. Looking onto it, you have text indents and negative margins causing the display to move out of visible range. Your CSS is not handling the active state correctly.
The next step is set up CSS for the active state.
ul#nav li.active { text-indent: 0; margin: 0; )
ul#nav li.active a { text-indent: 0; margin: 0; )
use that for starters – until you see the display on screen. Then adjust the margins to where you want the display appearing.
Work with that one simple UL/LI code block until everything displays just as you want it. Then add in the hover state, step by step. Make one small change at a time.
Only add in the dynamic PHP stuff after you get the static code styling working correctly. Debug one step at a time, from the most basic.
CSS dropdown menu systems are very difficult to code correctly. I generally suggest starting with a theme that already has working drop down menus, and modifying it. You are in too deep for that, but next time consider that.