SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Aug 2004
    Location
    KENT, UK
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    using php in css

    I am just starting out in css, having developed websites 'for fun', someone has now asked me to do a 'proper' one.

    I am prototyping for them at present and have been inundated for colour-request changes

    So I have put
    <?php

    Header ("Content-type: text/css");

    //default colors
    $backcolor = '#FFFFCC'; //used for overall backgroud
    $textcolor ='#660099'; //used for body text


    //top banner colors
    $blockcolor ='#330066'; //used for top banner
    $blocktextcolor='#666699'; //used for top banner text

    //bottom banner (eyecatcher) colors
    $eyecatchcolor ='#330066'; //used for bottom banner background
    $eyecatchtextcolor='#FFFFCC'; // used for bottom banner

    //menu colors
    $menucolor='#330066'; // used for menu bar bakground
    $currentmenutextcolor='#FFFFCC'; //used for cuurent menu option
    $menutextcolor='#666699'; // used for non-current menu options

    ?>

    at the top of the css and then am using statements like

    background-color?=$backcolor?>;

    which means I only have to change the colours at the top of my style sheet.

    I would welcome any comments on this - is it good practice/crappy or what?
    It works on my PC but that doesn't mean it's actually going to work everywhere.

    Advice please!!

  2. #2
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    40,546
    Mentioned
    183 Post(s)
    Tagged
    6 Thread(s)
    Hi,

    I haven't had any experience of using php with css but there was a discussion here which you might find useful.

    http://jeffcroft.com/blog/archives/000174.php

    It seems that the php css file doesn't get cached in the same way but you can read about it in the above link.

    However I have to wonder if php is necessary at all if you stucture your css to work like you want you can do things like this.

    Code:
    /* main bg colours*/
    #topbanner, #middle banner, #bottombanner
    {background:#FFFFCC}
    Now you only have to change the one colour which is exactly the same as your php file. I know its not quite the same but you get the idea

    Paul

  3. #3
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Off Topic:

    Unless you're storing user preferences in a database or changing the branding of a site for use by multiple companies, I can't really think of a good reason to mix PHP and CSS.

  4. #4
    SitePoint Member
    Join Date
    Aug 2004
    Location
    KENT, UK
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In my production release, I will NOT use php in css. but it seemed like a good way of prototyping, by letting the user change colours via a separate page and previewing until they find a colour scheme they like.

    No matter how many times you talk about it, until they actually see it, users never seem to be able to say yes or no!

  5. #5
    Drop em if you got em
    Join Date
    May 2003
    Location
    NY
    Posts
    691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For one of my sports sites I'm about to have the team pages be in team colors. There's a default color set now, and in the header I'll override certain styles with the team colors.

    There are a few other instances where I see throwing a scripting language into your css being a good thing.

  6. #6
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    40,546
    Mentioned
    183 Post(s)
    Tagged
    6 Thread(s)
    by letting the user change colours via a separate page and previewing until they find a colour scheme they like.
    Well if its only for initial design purposes then I suppose its whatever makes your job easier

    If your client can change colours etc until they find something they like then I suppose that could be a good thing. However I would assume that you will only allow them to have a choice from suitable alternatives so that accessibility issues are taken care of and colours that make sense together.

    Paul


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •