Jump to content

CSS Active State not working?


liamloveslearning

Recommended Posts

Hi all, I have a tabbed navigation showing a hidden div relating to the tabbed link clicked.

I want to set the active state so my users know which tab they are on.

 

my css is...

#tabbar {background-image:url(../images/tab-bg.jpg); background-repeat:repeat-x; height:30px;}
#tabbar a{padding:4px 6px; float:left; display:block; height:32px; color:#666; text-decoration:none; font-weight:bold; text-shadow: white 0px 1px 0px; }
#tabbar a:hover{color:#666; background-image:url(../images/act-tab-bg.jpg); height:22px; display:block; background-repeat:repeat-x;}
#tabbar a.tablink:active{color:#ff0000; background-image:url(../images/act-tab-bg.jpg); height:22px; display:block; background-repeat:repeat-x;}

 

and my html..

<div id="tabbar">
<a href="#tab1" class="tablink">Itinery</a>
<a href="#tab2" class="tablink">FAQ's</a>
<a href="#tab3" class="tablink">Locations</a>
</div>

Link to comment
https://forums.phpfreaks.com/topic/218300-css-active-state-not-working/
Share on other sites

:active is a deceiving name, as it does NOT relate to the page you are on. This is the state that happens after a link is clicked, before the next page has reloaded.

 

If you want a state that is relative to the page you are on, you can do this in your CSS by setting an ID on your body tag for each page, then using that ID to hit the element for the page you are on. Ex:

 

page 1 HTML:

<body id="page1">
  <ul>
    <li id="link1">Page 1 link</li>
    <li id="link2">Page 2 link</li>
   </ul>
</body>

Page 2 HTML:

<body id="page2">
  <ul>
    <li id="link1">Page 1 link</li>
    <li id="link2">Page 2 link</li>
   </ul>
</body>

CSS:

li {color:blue;}
#page1 #link1, #page2 #link2 {color:red;}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.