Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

HTML Background Image

Options
  • 03-07-2006 10:49pm
    #1
    Closed Accounts Posts: 8,866 ✭✭✭


    Hopefully there's an easy enough answer to this but for all my googling all I can seem to find is sh1te results!

    I just want to know how I can set an image as a background to an entire page, which will resize to the dimensions of the individuals browser, so there are no scroll bars etc.

    Its just a temp thing at the moment, before a debate background images ensues! :p


Comments

  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    <body background="./path/to/image.jpg">

    :)


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Alas no, that just plonks the picture in the page, it doesn't resize it at all! :(


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Oh resize, missed that.

    Not sure. You may have to embed some javascript use the onLoad and onResize handlers (if the latter exists) to dynamically resive the image.


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    I was thinking i ight have to do some such... :rolleyes: Its never simple is it!

    Anyone have any idea how this might work?


  • Closed Accounts Posts: 7,145 ✭✭✭DonkeyStyle \o/


    I was curious about this myself, so I kinda fudged something together that seems to work.
    <html>
    <head>
    
    <style type="text/css">
    
      body 
       {
         padding: 0;
         margin: 0;
       }
    
    
      #mybgimage 
       {
         width: 100%;
         height: 100%;
         float: left;
         z-index: 1;
         position: absolute;
       }
      #mybgimage img
       {
         float: left;
       }   
    
      #content
       {
         margin-top: 15px;
         z-index: 2;
         position: absolute;
         width: 60%;
         left: 20%;
         border: 1px solid #000;
         background-color: #FFF;
       }
    
    </style>
    
    </head>
    
    <body>
    
    <div id="mybgimage">
      <img src="my_image.jpg" width="100%" height="100%">
    </div>
    
    <div id="content">
       <p>Niiiih, spork? <br> OMG</p>
    </div>
    
    </body>
    </html>
    
    Wouldn't count on it validating though on account of the width and height attributes in the img tag... don't think even html4 transitional allows those, but what can ye do :rolleyes:


  • Advertisement
  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Nice thinking DS.

    Surely you can set a style for the img (give it an ID), and set the height and width attributes there to make it validate?


  • Closed Accounts Posts: 7,145 ✭✭✭DonkeyStyle \o/


    Oh yeah, that works... splendid stuff old chap.

    Here's the validatable version...
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Splendid old page indeed!</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <style type="text/css">
    
      body 
       {
         padding: 0;
         margin: 0;
       }
    
    
      #mybgimage 
       {
         width: 100%;
         height: 100%;
         float: left;
         z-index: 1;
         position: absolute;
       }
      #mybgimage img
       {
         float: left;
         width: 100%;
         height: 100%;
       }   
    
      #content
       {
         margin-top: 15px;
         z-index: 2;
         position: absolute;
         width: 60%;
         left: 20%;
         border: 1px solid #000;
         background-color: #FFF;
       }
    
    </style>
    
    </head>
    
    <body>
    
    <div id="mybgimage">
      <img src="my_image.jpg" alt="">
    </div>
    
    <div id="content">
       <p>Niiiih, spork? <br> OMG</p>
    </div>
    
    </body>
    </html>
    
    Pfff javascript indeed :D


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Nice one lads, cheers!


  • Registered Users Posts: 35,524 ✭✭✭✭Gordon


    Now I think we can get onto the topic of why on earth you want a resizable background image...

    :D


  • Closed Accounts Posts: 4,655 ✭✭✭Ph3n0m


    heh, now do it without absolute positioning :)


  • Advertisement
  • Closed Accounts Posts: 7,145 ✭✭✭DonkeyStyle \o/


    Gordon wrote:
    Now I think we can get onto the topic of why on earth you want a resizable background image...

    :D
    Yus, post linkies tbh. o_O
    Ph3n0m wrote:
    heh, now do it without absolute positioning :)
    No, only Chuck Norris can do that.


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    www.cavanrock.com

    Its under construction :D


Advertisement