#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Location
    England
    Posts
    45
    Rep Power
    11

    Dynamic CSS Problems


    Despite looking through the forum, having problems with dynamically creating an external CSS file. Can any one explain?

    Basically I currently have a CSS file:
    Code:
    .normal
        {
        font-family: Verdana, Arial, Helvetica, sans-serif;
    
        font-size:   11px;
        }
    
    .userdef
        {
        font-family: Verdana, Arial, Helvetica, sans-serif;
    
        font-size:   12px;
        color:       #FF0000;
        font-weight: 800;
        }
    
    .big
        {
        font-family: Verdana, Arial, Helvetica, sans-serif;
    
        font-size:   12px;
        }
    I have set the site up so that the user can define there own colour of text for the userdef style, but im unsure how I can put this colour variable into the CSS file. I'm guessing I have to rename it into a .php file... but how will the browser still know its a CSS file??


    Thanks very much for your help
  2. #2
  3. AZbb founder
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Location
    London, UK
    Posts
    843
    Rep Power
    11
    If it is only ONE element, then it would not be wise to read/write to external files.

    - Create your normal CSS, then way you like.
    - In the disaply page, import it ie.
    <link rel="stylesheet" href="yourcss.css" type="text/css">
    - After above entry add a style tag

    PHP Code:
    <link rel="stylesheet" href="yourcss.css" type="text/css" />
    <style type="text/css">
    <!--
    <?php
    echo ".userdef    {color: #$user_color; }";
    ?>
    -->
    </style>

    </head>
    - The above declaration would override the entry in yourcss.css
    - Now all you have to do is to feed $user_color ie $user_color = 'FF0000'; or get it from $_POST.


    This is a quick guide. You have to work on it. Make sure you have a default value and do not pass blank to $user_color


    Good luck



    ps. Better still:

    PHP Code:
    if (isset($color))
    { $user_color = ".userdef    {color: #$color; }"; }
    else {$user_color = "";}

    ## inside the styles:
    echo $user_color;
    <style type="text/css">
    <!--
    <?php echo $user_color?>
    -->
    </style>
    All you have to do is to get $color
    Last edited by Clan admin; April 8th, 2004 at 05:32 PM. Reason: Added code
    AZ

    AZbb :: AZ Bulletin Board - Secure BBS script, Front page CMS, Chat, No database
    Simple Guide to Apache and PHP installation on Windows

IMN logo majestic logo threadwatch logo seochat tools logo