Hi, I am trying to give an active state to my links and I almost got it
but the cant seem to get the same size as my hover state for the background
color I know it has to do with the padding. Website
That is the correct behavior. The “active” state is only while the mouse button is down, but old IE was confusing as it used “active” as any good browsers used “focus” and kept the state after mouse-up. Sorry but w3scools isn’t allways a reliable source.
What I think is the easy fix to your original post: Try move the active class’ white background from the anchor to the list item, then the whole item will get the white active color.
Both of these have class=“active” - simply remove the class from the one you don’t want highlighted.
I’d also suggest that you use a different classname in place of active as it can be hard to tell the difference between a.cactive and a:active which have completely different meanings.
As @felgall said, have the “active” class on only the menu item that links to the current page
That means you have to edit the menu on every main page you link to in the menu.
Another method is to have different active class names for each main menu link. Then you can have all classes put into every page’s menu. In the body tag on the corresponding pages you put a class that tells what menu item should get the current page highlighting, preferrably the same class name.
The current page’s highlighting then is changed according to the class name(s) in the body tag. Submenu pages’ body tag can have a sub page class added, same as in the submenu item.
Body tags:
<body class="home"> <!-- marker on the Home page -->
<body class="about"> <!-- marker on the About us page -->
<body class="products"> <!-- marker on all of Products item's linked pages -->
<body class="products shock"> <!-- marker on the Shock Indicator Labels' page -->
Fully automatic highlighting:
With knowledge of what “serverside language” your host server uses, you can have the server automaticly print the class name(s). You put a serverside script in those menu-linked pages’ body tags’ class-attribute that lets the server identify the page by name or path and put appropriate class name(s) in. With knowledge of how the script you wrote constructs the class names you can put those classes in the menu items.
Now every page has the same markup and the same css, giving the current page highlighting to the corresponding menu item on all menu-linked pages.
Automatic highlighting can of course also be achieved with a javascript choosing the appropriate class to put in the body tags on identified pages.
Nope. The anchor font color is the one that has the text inside of it.
The anchor has its own color set. The child would normally inherit the color from the parent, but since the anchor has a defined color, it will use that instead of the parent.
That’s why setting it on the <li> will do nothing.