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

    Join Date
    Jan 2003
    Posts
    83
    Rep Power
    12

    changing css styles with php


    I have a header.inc and a css style sheet that are called to each page of a website via php. In the style sheet there are two styles that I would like to change depending on the section of the website.

    For example:
    in the style sheet
    css id "subnav" has background: #E8EDF5 and
    cssi id "subtitle" has background #E8EDF5

    however in each major section of the website I would like to change the background colors of the divs that have id "subnav" and "subtitle".

    Is there type of php statement that I could place at the top of my website pages that would allow me to specify the colors of these two css ids?

    Hope I have made this clear.
  2. #2
  3. Updated
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    Sweden
    Posts
    124
    Rep Power
    12
    Short answer: No.
    Long answer: Yes, but you'll have to create a script that output the css based on the page calling it. Another way is to create diferent style sheets for every section. Or you could place the statements subnav and subtitle in a <style> in the page you create and not in the style sheet...
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2001
    Location
    Finland
    Posts
    716
    Rep Power
    51
    PHP Code:
    <?php
    if(<-- statement -->) {
     
    $bgcolor1 "#FF0000";
    }
    else 
     
    $bgcolor1 "#E8EDF5";
    ?>

    <head>
       <style>
    .subnav{
    background-color: <?php print $bgcolor1?>;
    }
      </style>
    </head>
    If that's not ok, then you could make several CSS files and include the one with correct colors

    PHP Code:
    <?php
    if(<-- statement -->)
    print 
    "<link rel=\"stylesheet\" type=\"text/css\" href=\"style1.css\">";

    else 
    print 
    "<link rel=\"stylesheet\" type=\"text/css\" href=\"style_default.css\">";
    ?>
    Fatal error on row 561: Couldn't access life - life isn't set
  6. #4
  7. Daniel Schildsky
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Mar 2004
    Location
    KL, Malaysia.
    Posts
    1,553
    Rep Power
    1621
    Originally Posted by jarow
    I have a header.inc and a css style sheet that are called to each page of a website via php. In the style sheet there are two styles that I would like to change depending on the section of the website.

    For example:
    in the style sheet
    css id "subnav" has background: #E8EDF5 and
    cssi id "subtitle" has background #E8EDF5

    however in each major section of the website I would like to change the background colors of the divs that have id "subnav" and "subtitle".

    Is there type of php statement that I could place at the top of my website pages that would allow me to specify the colors of these two css ids?

    Hope I have made this clear.
    besides using Kimppa's method, u can also try 2 override the div tag style using style attribute....
    set the style attributes with the desired colour using php script...
    Last edited by tvc3mye; March 12th, 2004 at 11:29 AM. Reason: correction....

IMN logo majestic logo threadwatch logo seochat tools logo