540 users online (0 members and 540 guests)  

  Results 1 to 2 of 2


  1. Cell background color    Forum: CSS Forum
    Replies: 5
  2. input boxes background color problem    Forum: CSS Forum
    Replies: 23
  3. Replies: 3
  4. background-color and NetScape 7 problem    Forum: CSS Forum
    Replies: 1
  5. Replies: 2
  1. #1
    tenors703's Avatar
    New User

    Join Date
    Feb 2005

    Background-color problem

    Hi all. I am new to CSS and php and am trying to display a <p> tag with a particular rgb value that I have stored in three variables. However, the background color doesn't change. When I look at the generated HTML it shows that the background-color is actually #26213d52587f even though it was supposed to only use two digits from each value according to my printf... Does anyone know why?

    Here's the code:

    // these values are actually calculated previously by the code
    // but here are their values when it gets to this point.
    $secondary_r = 2621;
    $secondary_g = 3d52;
    $secondary_b = 587f;

    // I think this is my problem... am I printing it correctly?
    printf( '<STYLE TYPE=\"text/css\"> p {background-color : #%02x%02x%02x;} </STYLE>', $secondary_r, $secondary_g, $secondary_b );

  2. #2
    QuietDean's Avatar

    Join Date
    Oct 2000
    Bournemouth, UK
    Hi, welcome to the forums.

    forgive my ignorance, whilst I code php for a living yet I have never used printf

    Checking the php.net manual page, I see an example of limitng characters:

    printf("[%10.10s]\n", $t); // left-justification but with a cutoff of 10 characters
    Have you tried this format?
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

Tags for this Thread