Stretchable Background in a Webpage

Ah ha! I have came up with a simple solution to make a background that stretches to fit the whole window in a webpage, by using css (that is, until CSS 3 comes)

Here is the compatibility status for this:

Works 100%:

  • Firefox
  • Opera

Works with Minor Problem:

  • Google Chrome
  • Safari

(The only problem with those is that they kind of cut off at the bottom of the page)

Doesn’t work at all:

  • Internet Explorer

(That shouldn’t really come as a surprise)


How to get it onto your web page:

Pretty much just put this into your web page’s header:

<style type=”text/css”>

/* Background start */

img.bg
{
z-index:-1;
width:100%;
height:100%;
_width:0%;
_height:0%;
position:fixed;
attachment:fixed;
left:0;
top:0;
}
</style>

And put this somewhere in your webpage (preferably right after the opening body tag):

<img class=”bg” src=”Image Link here“>

But of course change the Image Link here to the location of your background image.

One Response to “Stretchable Background in a Webpage”

  1. ashfueqwdf Says:

    lulz wut nice

Leave a Reply