General Question

Link's avatar

Background images in HTML?

Asked by Link (327points) June 26th, 2009

How do Web designers get background images to stretch across the entire page (vertical and horizontal)? What kind of images do they use? Don’t these large images create large file size?

Observing members: 0 Composing members: 0

15 Answers

Bri_L's avatar

Here is a link that explains things rather nicely.

I really like this sight in general.

http://reference.sitepoint.com/css

wenn's avatar

@Bri_L sitepoint has some good reference.

@Link take a look at the background of Fluther, the patter with the gradient over it. if you have Firebug for Firefox or have Safari version you can find the image used for the background. for Fluther the image is 131px wide and 738px tall and then using CSS it is set to “repeat-x”. and the image used is only 18kb so pretty small.

SecondGlance's avatar

@wenn is correct about the repeating patterns. Those can be very small images if done right.

I wonder if you are talking about the newer trend of full-screen images. To have a single image, like a photo, that fills an entire display, you will have a larger file size. The key here is to use Photoshop or something to reduce the resolution/size of the file so it’s reasonable. You have to account for the largest display size, perhaps 24” monitor is safe. Many Twitter/MySpace/other backgrounds look plain silly on my 22” monitor because they are small and end up sitting in the top left corner surrounded by blank space. You can see one page here, where I used a massive image (photo with black center) for the whole background – www.blogtv.com/People/SecondGlance It’s physically huge, and I centered it so it’s the same on any display.

Here’s the code (before the body tag) that made it happen:
<style type=“text/css”>
body {background: url(yourphoto.jpg) fixed center no-repeat;}
</style>

Cheers

Bri_L's avatar

@SecondGlance – Thanks for that example!

Link's avatar

Okay thanks to all. What exactly does “repeat-x” mean/do?

Link's avatar

NVM I figured it out. @Bri L: thanks!

dynamicduo's avatar

There’s a few ways.

The old school way is via the body tag, using any image that can be tiled horizontally and vertically such as these ones. Oh my, even just looking at those images brings back the nostalgia of old web design! You can also make a tiled image in Photoshop, search for ‘photoshop tutorial tiling image’ probably to find out how. Here’s the code for the body tag version.

The full control version, and easier way in general, is done through CSS. There are links here already for that, google for “css background image” (try with the word tutorial) to find more tutorials.

As for bg image size, yes this is something to consider, but not in all cases. Tiled backgrounds take up very little space as they are usually a few hundred pixels square (some are even as small as 20 pixels etc). Sometimes you need a full screen bg and yes it’ll be a few hundred kilobytes (try to make it under 600, people won’t wait around all day) but it can be done if you really need to. But there are a lot of tricks to doing BGs.

As always, I recommend observing. You can do it right here in Fluther. Case study time! Right click and view this page’s background (http://davinci.fluther.com/static/images/v2/wallpaper.jpg). 131 by 738 pixels tall, it’s about 19 kilobytes, and a jpg [I bet you could save even more kilobytes by making it a gif as this is the perfect image candidate to do such with, but honestly, we’re not designing for microbandwidth here]. The code to insert it (go and find this code, look at it, tell me if you can’t find the CSS code and I’ll tell you how to do that) has a repeat-x, hence it repeats along the top. The trick here is that the rest of the page has its background color set to the same dark blue as we see in the image, hence it looks like the background is seamless but in actuality it’s just a hidden seam.

Above everything else, consider your audience. Designing an iPhone site for instance, one that fully configures and looks like an app, you have the flexibility to hard code your background and DIVs, so by creating an optimized jpg or gif background, you can incorporate one in with relatively no delay for the user.

And one last tip from me. A lot of learning web design is getting into the code and figuring it out for yourself, or at least giving it a shot (not to discourage you from asking your questions of course!). The magic of web design is that if you can see it on the screen, generally speaking you can access the code (as long as it’s not in Flash, and you can’t do this for server side languages), you can save a copy of the website and get in there with your HTML editor and figure out just exactly how they did that awesome BG or whatever you see. Have you seen this website, Smashing Magazine? I think you will enjoy it, it contains a lot of information and ideas which for us designers is pretty much a goldmine! Oh, look at that, they even have a wonderful article with examples of tons of backgrounds! Sure they don’t have any code there, but that’s cause you don’t need it, you can figure it out for yourself. Take this site, looks really complex eh? Not really, look at the bg image: http://blog.raduceuca.com/wp-content/themes/warlord/assets/images/backgrounds/header_background.png Hohoho, that takes a lot of mystique out of it doesn’t that! Now you can see that the design is based a lot on positioning of DIVs, try deleting that BG and coloring the DIVs different solid bg colors. Cut out all the content and play with the tags, look them up in W3 and find out what they do!

Link's avatar

@Dynamic: As always, thanks for all your help. You’re by far the most helpful person I’ve ever met (on the internet =D). All the examples you provided were on the money, and you made my whole bg color issue seem so simple. I am motivated by how enthusiastic you are with Web design. I’m going to take your advice and start playing with the positioning and coloring of divs until I get the hang of it . Thanks again.

-Link

martijn86's avatar

There is a beautiful way to scale images to full size, no mather the viewport/resolution of the viewer. It’s called supersized.

It used jQuery wich is AJAX.. might sound scary for a HTML coder at first but this website explains everything very well in steps:

http://buildinternet.com/2009/02/supersized-full-screen-backgroundslideshow-jquery-plugin/

bonus's avatar

@dynamicduo I am just beginning to dip into learning some of this for myself. I really appreciate your above comments. Out of curiousity, how would you rough out a site? In other words, do lay in the infrastructure with some bold strokes in Dreamweaver and then fine tune it in a text editor? I am just wondering how you guys go about the process in a very general outlined sense.

Thanks.

martijn86's avatar

@bonus There’s a quick way to get good valid outlines: http://www.code-sucks.com/css%20layouts/

Just never go rough in Dreamweaver. Web- design/development should be done with care and precision. You’ll want 100% popular browser compatibility so you should check every step to see how in renders. Sketch, measure and calculate every size, spacing.. you name it. Take a little time for it.. and before you throw logo’s and fancy style in it, save the lay-out as a template for the next time!

wilhel1812's avatar

Its possible to do it with an image with 100% width and height.

bonus's avatar

@martijn86 Let me rephrase that. What is the primary program you guys favor for this type of work? It seems arduous to do it all in a text editor solely…

wenn's avatar

I use Photoshop, Illustrator, Flash(if I have to), and I use Textmate for writing all my code.

I have done projects in Processing and Nodebox also.

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther