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

    I'm not sure what you mean but here's a few ways of doing what I think you're asking.
    index.php

    <?php
    $bgcolor='#fff';
    include('./header.inc');
    //page stuff
    include('./footer.inc');
    ?>
    

    Header.inc

    <html>
    <head>
    <link rel="stylesheet" type="text/css" href="path/to/style.css" />
    <style type="text/css">
    /*because this is set after the stylesheet is included it will be the value*/
    body {
      background-color:<?php echo($bgcolor);?>;
    }
    </style>
    </head>
    <body>
    

    Or I believe you can pass get variables to a css file and then call it .php and the variables will be picked up by php.

    header.inc

    <!-- etc -->
    <link rel="stylesheet" type="text/css" href="path/to/style.php?bgcolor=fff" />
    <!-- etc -->
    

    style.php

    body {
      babground-color:#<?php echo($_GET['bgcolor']);?>;
    }
    

    I haven't ever tried the second method before but I'd be interested as to whether it works or not 🙂
    HTH
    Bubble

      it probably will, as the browser has to make a seperate request to get the styles.

        Write a Reply...