Home

Advertisement

Random images as a background in HTML

  • Feb. 6th, 2009 at 9:17 PM

Originally published at Random Geekage You can comment here or there.

A nice wee gem that Alex Peake informed me was possible. The problem: you want a randomly chosen image as a background but don’t want duplication in your css.

In your css file:

background-image: url('images/background.php');

Create the file referenced above with this code:

<?php
    $numofimages = count(glob("*.jpg"));
    $imagenum = rand(1, $numofimages);

    header("Content-Type: image/jpeg\n");
    header("Content-Transfer-Encoding: binary");

    $fp=fopen("headerimage". $imagenum .".jpg" , "r");
    fpassthru($fp);
?>

and voila, random images as a background with the bonus of being able to throw in a new image without having to do any more coding.

This code assumes that your images are called headerimageX.jpg where X is a number.

CSS is a pain UPDATE: sorted

  • Oct. 5th, 2008 at 1:58 PM

Originally published at Random Geekage You can comment here or there.

Update 06/10/08: Got it sorted

CSS is a pain in the ass sometimes. Everything seems to be fine yet the main content is appearing below my sidebar instead of side by side. I am told that this is because one element is probably too big and is being pushed out of alignment. My sidebar is 200 pixels with a 600 pixel left margin and floated right. The content is 600 pixels wide with a 200 pixel right margin and is floated left.

This is why I’ll never be a web developer.

Latest Month

December 2009
S M T W T F S
  12345
6789101112
13141516171819
20212223242526
2728293031  

Tags

Syndicate

RSS Atom
Powered by LiveJournal.com
Designed by Lilia Ahner