Include Function & Changing Link Colors

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Alex Cory
Forum Newbie
Posts: 2
Joined: Wed Mar 14, 2007 2:05 pm

Include Function & Changing Link Colors

Post by Alex Cory »

Hey all...this is my first post here, I'm excited to get involved.

Quick question for yah:

I am designing a basic PHP page with a footer at the bottom that contains navigational links to the rest of the website. To generate this footer I am using a basic Include function that references "footer.php" and inserts it into "index.php". Now, the background of "index.php" is white, so I want all of the links on it to be blue. However, "footer.php" has a black background so I want all of the links to be white. I use CSS in both pages to define the colors of the links.

Now, when I load the "index.php" page, the links on both "index.php" and "footer.php" are all white. The browser is taking the info i specify in "footer.php" and applying it to the whole loaded page.

Any help on this issue would be much appreciated! Thanks in advance.
User avatar
TheMoose
Forum Contributor
Posts: 351
Joined: Tue May 23, 2006 10:42 am

Post by TheMoose »

When PHP sees the include statement, it takes the code inside footer.php, executes it, and appends its output at the end of the index.php (or wherever the include statement is). If you have CSS statements set to HTML tags themselves, the last version is used, which is why you are getting the footer.php style on your index.php stuff. What you need to do is be more specific in your CSS styling, such as put your index.php stuff inside a DIV tag and give it an ID of index, and then you can do this:

Code: Select all

#index a {
   color: #0000ff;
}
And you could do the same for the footer/header info as well. This way it is separating which styles get applied to certain elements.

Or you could give specific class names to all your footer links, ie:

Code: Select all

<a href="#" class="footerlink">Linky</a>

CSS:
.footerlink {
   color: #ffffff;
}
Alex Cory
Forum Newbie
Posts: 2
Joined: Wed Mar 14, 2007 2:05 pm

Post by Alex Cory »

Moose...thank you very much. Your advice did the trick.

It's much appreciated!!!!!
Post Reply