changing css styles with php

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
jarow
Forum Commoner
Posts: 83
Joined: Tue Jan 28, 2003 2:58 am

changing css styles with php

Post 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.
User avatar
Pointybeard
Forum Commoner
Posts: 71
Joined: Wed Sep 03, 2003 7:23 pm
Location: Brisbane, AUS
Contact:

Post 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.
Morpheus
Forum Newbie
Posts: 6
Joined: Thu Mar 11, 2004 7:00 am
Location: South Africa

Post 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 ;)
Post Reply