Page 1 of 1

changing css styles with php

Posted: Thu Mar 11, 2004 6:24 am
by jarow
I have a header.inc and a css style sheet that are called to each page of a website via php. In the style sheet there are two styles that I would like to change depending on the section of the website.

For example:
in the style sheet
css id "subnav" has background: #E8EDF5 and
cssi id "subtitle" has background #E8EDF5

however in each major section of the website I would like to change the background colors of the divs that have id "subnav" and "subtitle".

Is there type of php statement that I could place at the top of my website pages that would allow me to specify the colors of these two css ids?

Hope I have made this clear.

Posted: Thu Mar 11, 2004 6:30 am
by Pointybeard
What about somthing like this:

Code: Select all

<link rel="stylesheet" href="<?= (page your on = major ? 'style1' : 'style2') ?>.css" type="text/css" />
Just have some sort of condition there. It looks at the page your on and decides which css file to include.

Posted: Thu Mar 11, 2004 7:00 am
by Morpheus
Well, the different sections of your site. Do it have different scripts that's running it? For instance section_1.php and section_2.php. If so, you can change the .css files (actually just have one) with a "section_1." in front of all your css entries. Then, in your code you go:

Use this if you've got 2 .css files with the same name classes in each one:

Code: Select all

<link rel="stylesheet" href="<?= (basename ($PHP_SELF) ;?>.css" type="text/css" />
Alternatively... if you have one .css file with the "section_1." in front of each class, you can put the "<?= (basename ($PHP_SELF))?>" in front of each reference to the class (if you're using the CSS in this way). Option 1 above is probably better :wink:

Anyways... good luck ;)