PrintedExistence[dot]com


(x)html & css


How to Code...




Donate


All this information & code is provided completely free of charge, but if you have some spare money, and wish to send me some for my trouble, please hit the button below!




JukeBox



Sponsor Ads





Backgrounds







Background Color

Background color (color always spelled the American way) can be set using the colors name, or its Hex code.

Browsers recognize an increasing number of color names, such as deeppink, purple, orange and red. You can find a full list of widely recognized color names [ on the w3schools website ]

Hex codes are a fully supported version of color names. Every shade of every color imaginable has a hex code. It's a 6 character code started with a # sign, for instance #ffffff is the hex code for white, and #000000 is black. You can find a pretty long list of hex codes on [ Webmonkey ].


To apply the background color to your whole page just use:

<style type="text/css">
html, body { background: deeppink; }
</style>

Applying a background to "table" or "div" will affect every table or div on the page, for example:

<style type="text/css">
table { background: red; }
</style>

Alternatively you might want to affect just one table or div box, that has a predefined class:

<div class="mybox">stuff in here</div>

<style type="text/css">
.mybox { background: #990000; }
</style>

You may have heard of "Websafe" colors...

In the bad old days, when the majority of computers struggled to show more than 256 colors, the websafe hexadecimal color chart was invented. It consisted of 216 colors that these systems could display cleanly. However, with the advent of modern technology, it's probably no longer necessary to take such precautions, since most computers can now display millions of colors.


top



Background Images

To make a background image show up on your page, you first need to upload it to the internet. Images saved on your computer will not work! If you're doing a profile or blog, there are a lot of ad supported hosts like [ Tinypic ] or [ Photobucket ] that will let you store your images online for free. These sites will give you a "link" or "url" to your image which starts with http:// and ends in some kind of image extension like gif, jpg or png. When you paste the image url into the code below, you must use the whole thing including the http:// bit.
If you're doing a full site, then you can upload your images to the same directory as your pages and use relative paths if you like, ie, myimage.gif, instead of http://www.mysite.com/myimage.gif.


To put a background image on your page itself:

<style type="text/css">
html, body { background: url('http://path to your image.gif'); }
</style>

You can also put a background image on a specific table or div box, defined by it's class, eg:

<div class="mybox">text text text</div>

<style type="text/css">
.mybox { background: url('http://path to your image.gif'); }
</style>

top



Color & Images Together

Sometimes you're going to want both a background image and a background color on the same part of your page, for instance, if your image isn't repeated and it only takes up a small part of the page, or if your background image provides the dark background necessary to make light text show up properly, but you're worried it might not load and people will struggle to read your page.


Some people use separate background-image and background-color styles, like this:

<style type="text/css">
html, body {
background-color: orange;
background-image: url('http://path to your image.gif');
}
</style>

There's nothing wrong with that, it does exactly the same thing as the code below and some people find it simpler, but I prefer the lazy all in one method:

<style type="text/css">
html, body {
background: #990000 url('http://path to your image.gif');
}
</style>

Which is just simply to write the color before the image path.

top



Background Repeat, Position etc.

CSS provides ways to define exactly how you want your background images to behave.


Background-Repeat

Background-repeat defines whether the image repeats. It can be either "repeat" (default), "no-repeat", "repeat-x" (repeats horizontally only), or "repeat-y" (repeats vertically only). For example, this code would make an image of your choice repeat vertically all the way down your page:

<style type="text/css">
html, body {
background: url('http://path to your image.gif');
background-repeat: repeat-y;
}
</style>



Background-Position

Background-position is where on the page you want your background to appear. It is usually 2 parameters one after the other- vertical position followed by horizontal position, for instance "top left" or "bottom center". Vertical position can be top, center or bottom, and horizontal position is left, center or right. Nb, top left is default. This example code will place a background image in the bottom right corner of the page:

<style type="text/css">
html, body {
background: url('http://path to your image.gif');
background-position: bottom right;
}
</style>



Background-Attachment

Background-attachment simply defines whether the image stays in the same position on the page, or moves down as the user scrolls down the page. It has 2 possible values, "fixed" or "scroll" (fixed being the still background). On this example the background image will not scroll with the text:

<style type="text/css">
html, body {
background: url('http://path to your image.gif');
background-attachment: fixed;
}
</style>

Nb, background-attachment only works on the page body, and the default value is scroll.

top



Multiple Background Images

One of the most common questions I get asked, is if you can have more than one background image on your page, for instance if you want one image in the top left corner, and another separate one in the bottom right. If you're familiar with HTML you'll realize that it's not a good idea to do this by making both images into one big image, as it will only work at one screen resolution, and will take ages to load anyway, but if you're familiar with CSS you'll know that you can't set more than one background on the same thing. So how do you do it then?

Well you could absolutely position it, but unless you have a pretty good idea what you're doing, absolute positioning can be err.. a bit dodgy, at best. Alternatively then, you could just add a transparent div or table over 100% of your page, and put all your page content in that. You then stick one background on the div box, and one on the page body itself, and your visitors are none the wiser:

<div style="height: 100%;" class="fullpagebox"> page content in here! </div>

<style type="text/css">
html, body {
background: url('http://path to your image 1.gif');
background-repeat: no-repeat;
background-position: top left;
}
.fullpagebox {
background: url('http://path to your image 2.gif');
background-repeat: no-repeat;
background-position: bottom right;
}
</style>

Nb, If you use this method be careful to set background position for at least one of your images, so they don't end up on top of each other, and don't give the div box a background color or the background image on the page body will be hidden by it! If you want a background color as well, only apply it to page body.

top
All content copyright PrintedExistence.com 2006 - 2007 ©
PrintedExistence.com is a subsidiary of StephensPhoto™

W3c Valid XHTML  W3c Valid HTML  W3c Valid Css  Get Macromedia Flash Player  Viewable With Any Browser  PHP Powered  MySql Powered
preloading...