SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: How to properly stretch a background so it occupies the entire screen?

  1. #1
    SitePoint Member
    Join Date
    Feb 2011
    Location
    Erie, Pennsylvania, United States
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to properly stretch a background so it occupies the entire screen?

    I'm new at developing websites, and I'm kind of stuck on a background layout. Can someone fill me in on how to have multiple colors in the background stretch
    the entire screen width? Please take a look at this site: www.realtrainingandfitness.com . You'll notice that it takes forever to load because all those color variations (the top black header, the middle silver content area, and the silver footer area) are one big image. I want to break them out into their respective containers but I'm not sure how to get them all to stretch the screen. Any help would be greatly appreciated.

  2. #2
    It's all Geek to me silver trophybronze trophy
    SitePoint Award Recipient ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, Australia
    Posts
    20,007
    Mentioned
    217 Post(s)
    Tagged
    3 Thread(s)
    Hi rbardo. Welcome to the forums.

    If you were prepared to do away with the photo in the background, you could do a very narrow slice of this image and set it to repeat across the screen. If you want the photo, you still should do that slice, and add in the photo separately, as a background image on the section it occupies.

    An alternative is to break the page into sections, each with its own repeated background image.

    The image in the site you linked to is way too large and grossly inefficient, so it's good that you are looking for an alternative!

  3. #3
    SitePoint Member
    Join Date
    Feb 2011
    Location
    Erie, Pennsylvania, United States
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey ralph.m. Thank you for the reply. I really appreciate the constructive criticism. This may sound like a stupid question, but what exactly do you mean by slice? I design my sites' in Fireworks. While I'm coding I just go into fireworks, grab the image I need, and save it as a .png in the root folder. Is that slicing? And for some reason I can't get the middle content background to repeat. any suggestions?

  4. #4
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,612
    Mentioned
    83 Post(s)
    Tagged
    1 Thread(s)
    Hi rbardo,

    Say your image in Fireworks, you select a 5 pixel by 5 pixel block. Copy that and save to a new bk_first.png file. Then in CSS you do something like:
    Code:
    #background_section_one{
      ...
      width: 33%;
      background-image: url(images/bk_first.png);
      background-repeat: repeat; /* repeat both x and y and fill the space */
    }
    Steve

  5. #5
    It's all Geek to me silver trophybronze trophy
    SitePoint Award Recipient ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, Australia
    Posts
    20,007
    Mentioned
    217 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by rbardo View Post
    what exactly do you mean by slice?
    What ServerStorm said, although in this case, because the bg image has various colors going down the page, you could crop it to the full height an, say, 10px wide. Then you can set it to repeat across the screen (repeat-x). It's better to do it this way when you have an image that doesn't vary horizontally. That is, a 10px wide slice contains everything that the full width image does. So you end up with a tiny image pixel-wise and et the browser do the work of displaying it across the screen.

    A very rough example (from a screen shot) is attached.

    bg.png

    If you save that image to your desktop and then open a .html file on your desktop with this code it it

    Code:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>Experiment</title>
    	
    <style media="all">
      body {background: url(bg.png) repeat-x;}
    </style>
    	
    </head>
    <body>
    </body>
    </html>
    You'll see how the image repeats across the screen. It's not perfect, because the image slice I took doesn't tile well, but you get the idea.

  6. #6
    SitePoint Member
    Join Date
    Feb 2011
    Location
    Erie, Pennsylvania, United States
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Man, I'll tell you what, you guys have been a tremendous help. I did what you said, and wow! What a difference. I should have been in this forum asking questions a long time ago. Thanks guys, I really appreciate it.

  7. #7
    SitePoint Enthusiast Albablue89's Avatar
    Join Date
    Jul 2005
    Location
    Scotland
    Posts
    98
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rbardo View Post
    Man, I'll tell you what, you guys have been a tremendous help. I did what you said, and wow! What a difference. I should have been in this forum asking questions a long time ago. Thanks guys, I really appreciate it.
    Put all your contents inside a wrapper (container).

    Your middle wrapper, grey part is floating left relative to the browser.

  8. #8
    It's all Geek to me silver trophybronze trophy
    SitePoint Award Recipient ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, Australia
    Posts
    20,007
    Mentioned
    217 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by rbardo View Post
    Man, I'll tell you what, you guys have been a tremendous help. I did what you said, and wow! What a difference. I should have been in this forum asking questions a long time ago. Thanks guys, I really appreciate it.
    Glad we could help! Hope we see you again soon.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •