Jump to content

A little problem i never figured.


cip6791

Recommended Posts

hi ...

 

I have a general header.php which I include in all my pages. I am building a static website.

How would like to make the button in the navigation be on hover like if user is on home page the home button stays a different color. and so on.

 

so i have this :

 

<li><a href="index.php" class="active">Home</a></li>

 

but since all the pages get the same page, how can i change the active class for each of my pages? there are 5 in total.

 

thank you

Link to comment
https://forums.phpfreaks.com/topic/129076-a-little-problem-i-never-figured/
Share on other sites

the php is included server side  not browser so it doesnt effect the display of things based on active states in css

 

 

    a:link              { color:red; text-decoration:underline; }

    a:visited          { color:red; text-decoration:underline; }

    a:hover            { color:green; text-decoration:underline; }

    a:active            { color:red; text-decoration:underline; }

 

This is easiest done with php. For each link you output, check to see if the link is the same as the page you are on. If it is, then output class="active" on that link. Then set a css class for .active that looks the way you want it.

 

It's also possible to do this entirely in CSS, though it will take more coding. The above way is the simplest.

If you don't know php, then a css only method is probably easier for you.

 

If you have some links, for example home, about, contact, then give each of those links an id with that name:

 

<a href="/home" id="home">home</a>
<a href="/about" id="about">about</a>
<a href="/contact" id="contact">contact</a>

 

then you give the body of each of those pages a unique id. So the home body will look like this:

 

<body id="home_page">

 

Then you set your regular css:

 

a
{
   color: black;
}

and you set the active links by using the body IDs:

 

#home_page #home, #about_page #about, #contact_page #contact
{
   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.