...

View Full Version : randomize in css sheet



jayvee
07-18-2008, 07:42 AM
i was wondering if u can randomize something in the css sheet.
example:

#header{height:450px; background:url(images/flash.jpg) top repeat; text-align:left;}

i want to randomize the "images/flash.jpg" part. so like randomize flash1, flash2, flash3 thxs in advanced.

BubikolRamios
07-18-2008, 07:52 AM
You can't. Use java script, or possible server side language, if jou are refreshing whole page each time.

jayvee
07-18-2008, 08:01 AM
o ok. is there a code snippet i can use for a resource? thanks

abduraooft
07-18-2008, 08:05 AM
You can't. Use java script, or possible server side language, if jou are refreshing whole page each time.
You can do it easily by the help of PHP!

Just save your CSS file with a php extension, say style.php of style.css.php

Then add a header at the top of your file, like


<?php
header( 'Content-type: text/css' );
?>


Now you can add and execute any PHP codes inside your file anywhere within PHP tags.

PS: the above would be applicable to any server-side languages, but simply I don't know :)

jerry62704
07-18-2008, 02:34 PM
I wonder if you have looked at expressions? I don't use them, but they allow you to dynamically change the css.

BoldUlysses
07-18-2008, 02:49 PM
Can't randomize the CSS but you can randomize the markup (HTML, XHTML) using PHP fairly easily. Rename the file extension of your page to .php and add:


<?php
$image = rand(1, 30);
echo '<img src="images/IMG_'.$image.'.jpg" "alt=Image '.$image.'" title=""/>';
?>

Where 1 and 30 are the upper and lower limits on the range of random numbers generated. Adjust as needed.

abduraooft
07-18-2008, 02:53 PM
I wonder if you have looked at expressions? I don't use them, but they allow you to dynamically change the css. AFAIK, they work only in IE, and it'd be hard to write a long procedure in the CSS expression

jerry62704
07-18-2008, 02:57 PM
I didn't know they were browser dependend. I don't use them as I'm afraid of the performance hit as they are evaluated for every move of the mouse on the page as well as start up and end time. I've got to look into that.

Thanks for the heads up.

Apostropartheid
07-18-2008, 05:40 PM
Can't randomize the CSS but you can randomize the markup (HTML, XHTML) using PHP fairly easily. Rename the file extension of your page to .php and add:


<?php
$image = rand(1, 30);
echo '<img src="images/IMG_'.$image.'.jpg" "alt=Image '.$image.'" title=""/>';
?>

Where 1 and 30 are the upper and lower limits on the range of random numbers generated. Adjust as needed.
Um, of course you can randomize a CSS stylesheet. PHP can send a HTTP Content-Type header for CSS and that's all that's needed. It's not an exclusive markup thing, you know...

BoldUlysses
07-18-2008, 06:03 PM
I stand corrected. So how would I structure a CSS stylesheet file to accept PHP input? Or rather, I suppose, how would I structure a PHP file so the browser treats it like a stylesheet?

Apostropartheid
07-18-2008, 06:38 PM
abdura has already said; simply make PHP output a CSS header.


<?php
header("Content-Type: text/css");
?>
@charset "utf-8";
html {
font: 75&#37;/1.8 'lucida sans unicode', 'lucida grande', sans-serif;
}
/* Et cetera */

BoldUlysses
07-18-2008, 06:50 PM
That's what I get for not scrolling up! Thanks :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum