Page 1 of 1

Include Function & Changing Link Colors

Posted: Wed Mar 14, 2007 2:15 pm
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.

Posted: Wed Mar 14, 2007 2:25 pm
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;
}

Posted: Thu Mar 15, 2007 12:32 am
by Alex Cory
Moose...thank you very much. Your advice did the trick.

It's much appreciated!!!!!