Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highlighting an active tab - CSS

Tags:

css

navigation

I have a small tabbed navigation setup using CSS. When hovering over the tabs the colour changes, great. However when i click a tab and it navigates to the corresponding page, i would like that tab (the active tab?) to remain highlighted, indicating the current page.

I am currently doing this by using a class (.currenttab ) and then using this class in each HTML file. I am not using:

active

Is there a way for me to use active, rather than using a class in each individual HTML file, or is what i am doing correct?

Thank you in advance.

like image 718
Ronnie Avatar asked Dec 31 '08 14:12

Ronnie


3 Answers

What you are doing is correct. The :active pseudo selector means something else - the event of activating a control (ie, the time between a user presses the mouse button and releases it).

Using a class to signify the selected item is the way to go.

like image 168
Eran Galperin Avatar answered Oct 01 '22 11:10

Eran Galperin


It's far from ideal, but if you give every page and every tab an id, you can define the highlighting in css instead of html. I ran across a full explanation while looking up the active attribute:

Highlighting Current Page With CSS

A site I designed with this technique (pages, not tabs)

like image 45
Justin Love Avatar answered Oct 01 '22 11:10

Justin Love


Here are some more examples brainjar Demo
More from Brainjar

like image 40
Kb. Avatar answered Oct 01 '22 11:10

Kb.