writing a php statement to change a css style

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

writing a php statement to change a css style

Post by jarow »

I have a header.inc file and a footer.inc file that is called to each new file that I create.

The header.inc file holds all the javascripts as well as calls the css, etc. It also begins the body and the footer.inc file closes the body. In other words in each new file that I create I have a php statement calling the header, and at the bottom of the file another statement that calls the footer. So each new file is really only part of the body as the title and head are found in the header.inc file.

What I would like to do is be able to change the background color of the body of a new file if I choose to do so. But obviously because each new file is only part of the body I cannot put a css style in the new file.

Is there any way of writing a php statement that I can place in a new file that would allow me to change the background-color of let's say #faunabody for that particular page??.

Hope this is clear...thanks alot
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

you could anywhere on the document put :

Code: Select all

<style>
background-color: somecolor;
</style>

or call a different stylesheet document:
<link href...
...even in the body
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

I would think about doing somethin like this:

Code: Select all

&lt;form action="other.php" method="post"&gt;
&lt;input type="text" value="csstype"&gt;
&lt;/form&gt;
other.php :

Code: Select all

<?php

$style = $_POST['csstype'];
switch($style){
    case 'choice1':
        $theFile = 'style1.css';
        break;
    case 'choice2':
        $theFile = 'style2.css';
        break;
}

?>
<link rel="stylesheet" type="text/css" href="<?php echo $theFile; ?>" />
I dunno if that will work as is, but hopefully you get the idea.

:)
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

I'd make the css file a .php file (yes, this is possible), and then include the css file with extra $_GET variables.

Such as:

<link rel="stylesheet" type="text/css" href="includes/css/file.php?page=main.php" />

Then within the file switch the background, or whatever, depending on the $_GET['page'] variable.
Post Reply