Generating dynamic css using php and javascript

Posted by Onkar Deshpande on Stack Overflow See other posts from Stack Overflow or by Onkar Deshpande
Published on 2010-06-16T19:49:17Z Indexed on 2010/06/16 20:02 UTC
Read the original article Hit count: 303

Filed under:
|
|

I want to generate tooltip based on a dynamically changing background image in css. This is my my_css.php file.

<?php
    header('content-type: text/css'); 
    $i = $_GET['index'];
    if($i == 0)
        $bg_image_path = "../bg_red.jpg";   
    elseif ($i == 1)
        $bg_image_path = "../bg_yellow.jpg";   
    elseif ($i == 2)
        $bg_image_path = "../bg_green.jpg";   
    elseif ($i == 3)
        $bg_image_path = "../bg_blue.jpg";    
?>
.tooltip {
            white-space: nowrap;
        color:green;
        font-weight:bold;
            border:1px solid black;;
            font-size:14px;
        background-color:  white;
        margin: 0;
        padding: 7px 4px;
        border: 1px solid black;
        background-image: url(<?php echo $bg_image_path; ?>);
        background-repeat:repeat-x;
        font-family: Helvetica,Arial,Sans-Serif;
        font-family: Times New Roman,Georgia,Serif;
        filter:alpha(opacity=85); 
        opacity:0.85;
        zoom: 1;
 }

In order to use this css I added

<link rel="stylesheet" href="css/my_css.php" type="text/css" media="screen" />

in my html <head> tag of javascript code. I am thinking of passing different values of 'index' so that it would generate the background image dynamically. Can anyone tell me how should I pass such values from a javascript ? I am creating the tooltip using

var tooltip = document.createElement("div");
document.getElementById("map").appendChild(tooltip);
tooltip.style.visibility="hidden";

and I think before calling this createElement, I should set background image.

© Stack Overflow or respective owner

Related posts about php

Related posts about JavaScript