Global Variables

Sabtu, 07 Mei 2011

HTML - Background

Bookmark and Share


Images can be placed within elements of HTML. Tables, paragraphs, and bodys may all have a background image. To accomplish this, we use the background attribute as follows.
Advertise on Tizag.com

HTML Code:

<table height="100" width="150"
 background="http://www.tizag.com/pics/htmlT/background.jpg" >
<tr><td>This table has a background image</td></tr>
</table>

Background Image:

This table has a background image

HTML - Background Repeat

In the first example we happen to be lucky because our image and our table had exactly the same size pixel dimensions. Everything looks great. When your HTML element is larger than the dimensions of your picture, the image simply begins to repeat itself.

HTML Code:

<table height="200" width="300"
 background="http://www.tizag.com/pics/htmlT/background.jpg" >
<tr><td>This table has a background image</td></tr>
</table>

Repeating Background:

This table has a background image
It is obvious this is often not the desired outcome, however, it can also be quite useful as you will see in the following example.

HTML - Patterned Backgrounds

Repeating a generic image as a background doesn't have much practical use. We either need to find an image to fit exactly as our background or have an image editing program to adjust the dimensions of our image.
From a different angle, we can use this default attribute to our benefit say if we wanted to have some sort of pattern as our background. In an image editing program such as Adobe Photosop, or Paint Shop Pro, we could create a very small (perhaps 4X4 pixels) and create a couple of basic patterns.

4x4 Image:

Now here is the same image set as the background to our same table.

HTML Code:

<table height="100" width="150"
 background="http://www.tizag.com/pics/htmlT/pattern.jpg" >
<tr><td>This table has a background patterned image</td></tr>
</table>

Pattern:

This table has a background patterned image
This technique is definitely one for the pros.

HTML - Transparent Background

Another great techinique, along the same lines as the patterned images, is that of transparent, colored backgrounds. Most image editors have some sort of transparency device to create images that appear see through. We're not going to cover how to do this with every single program, however, most of the time all you need to do is fill your canvas with the color you would like and then set the opacity to something below 100%. Then make sure you save your file as a gif not a jpeg, and all systems should be go.
Now that you have had the crash course on creating transparent files, you place them onto your websites the exact same way as you would a repeating background.

HTML Code:

<table background="http://www.tizag.com/pics/htmlT/transparent.gif" >
<tr><td>This table has a red transparent background image</td></tr>
</table>

Transparent:

This table has a red transparent background image


Bookmark and Share


Tips

  • When creating patterns or transparent gifs, use the smallest dimensions possible even as small as 1x1 if you can. Larger files load slow and inhibit the load time of your sites.
  • Experiment, tinker, and fiddle around with your backgrounds to come up with something enjoyable to look at. Be creative.


Found Something Wrong in this Lesson?

Report a Bug or Comment on This Lesson - Your input is what keeps Tizag improving with time!

0 komentar:

Posting Komentar