tags:

views:

33

answers:

1

Hello guys,

i have a basic two column webpage i did with css. it includes a header,footer,sidebar and bodycontent.

i'd like to generate css attached to the document dynamically so it will change the arrangement and color.

if i open the page with urlencoded values like page color, body color, sidebar position(left or right).

i can do this manually, by changing css values, but i want php to do it for me

how do i go it? is there any simple framework for this

+2  A: 

I would store any cross layout similar styles in an external style sheet and then say:

<style type="text/css">
    body
    {
        background: <?php echo $bgcolor; ?>;
    }

    #wrapper
    {
        margin: 0 auto;
        width: <?php echo $wrapper_width; ?>;
    }
</style>
Josh K
How would you go about saving this and calling it from a html page? Would you have to add `Content-Type: text/css` to pass it as a css file? I'm just curious.
Russell Dias
I don't believe it is required, but it definitely wouldn't hurt to send the content-type across.
Joseph
@Russell: You would strip off the `<style>` tags on top *and* bottom and save it as something like `style.css`. In your html file you would use a `link` tag to link to it.
Josh K
@Josh: Renaming it .css will most likely then NOT run the script through the PHP parser. You'd have to reconfig the server to treat .css as PHP scripts, or leave the filename as .PHP. But then you also have to consider that the output may not be cached, forcing the style sheet to be retrieved for every page hit.
Marc B
@Marc: Ah, I had a bit of a LOBF there. As mentioned, put all styles in an external style sheet and then put this style block for any dynamic styles you need to set via PHP.
Josh K
The solution i currently do is that i made up to 20 css styles, and when calling the page, i attach the number for the css style i want as a GET request. and use php to load directly
Smith
@Smith, that could work.
Josh K