HubsInfo Network

Randomize Background Image with PHP and CSS3

0 Members and 1 Guest are viewing this topic.

Randomize Background Image with PHP and CSS3
« on: February 23, 2014, 03:20:11 PM »
Randomize Background Image with PHP and CSS3


PHP

Code: [Select]
// Randomize Background Image with PHP and CSS3.
$bg = array('bg-01.jpg', 'bg-02.jpg', 'bg-03.jpg'); // array of filenames
$i = rand(0, count($bg)-1); // generate random number size of the array
$selectedBg = "$bg[$i]"; // set variable equal to which random filename was chosen
?>


HTML/CSS

Code: [Select]
body{font-family: 'Amarante';margin: 0;background:#000 url(/images/) top center no-repeat;}