![]() | BACKGROUND ALTERATION! | ![]() |
Sponsor Links Free Image Hosting Your source for free image hosting - upload your images! Poker Strategies and Tips Poker, online poker, poker terms, poker accessories, poker tips and tricks. Photoshop Tutorials Over 3,000 tutorials for Photoshop, Flash and 3DS Max! 6,000 Free Fonts Download over 6,000 Free Fonts for Mac and PC @ FontVillage.com Buy Website Visitors 1,000 Targeted U.S. Visitors for $3.50 - 30 day guaranteed. Reading Tarot Cards Videochat with certified tarot readers & psychics - unlimited tarot cards readings! Affiliate Software Start an affiliate program and design to maximize affiliates' productivity PPC Search Engine Low cost advertising for your website! Technical Service Provider Your number one source for computer repairs and network solutions | LESSON 1-06-01: Changing Background Colors Web Design Lessons > Lesson 1-06-01: Changing Background Colors
This section of your free online web design course is going to teach you how to add a background color to your HTML documents, HTML tables, table cells and even your texts! We're going to start off by adding a background color to the whole web page. HTML Document Background ColorsIn order to change the background color of your HTML document, we are going to add a special attribute, called "bgcolor", to the <body> tag, and assign a color value to this attribute. Copy & paste the below HTML code to create a blank HTML document with a black background:
The output of the above HTML code is below: We can set the value for the "bgcolor" attribute as a color hex code as well. Let's set it to "#99CCFF", which is a web safe color (Sidenote: If you do not know what I am talking about, go to Lesson 1-04 to learn all about web safe colors and color hex codes):
The above HTML code will produce a blank HTML document with "#99CCFF" as the background color: HTML Table Background ColorsWe're going to continue our free online web design course by learning how to add a background color to tables. It is very similar to adding a background color to an HTML document, as the same attribute (bgcolor) is used to assign a background color to a table. We'll insert the bgcolor attribute inside the <table> tag just like we did with the body tag above:
In the above HTML code, we have created a table with a background color of "#FFCC00" inside an HTML document which has a background color of "#99CCFF". The output of this code is below:
As we did not define a table border in the source code, our table doesn't have borders, but the background color still makes it visible. HTML Table Cell Background ColorsNext in Online Web Design Course, we're going to learn how to add a background color to individual cells of a table. This is achieved by using the "bgcolor" attrribute with the <td> tags. Below is an example HTML code:
As you can see, we have added the "bgcolor" attribute to both of the <td> tags. Let's see what the above HTML code looks like in a browser:
Hmmm... Looks like we have "borders", although we never assigned a "border" attribute to our table. What may be wrong? Those are not real borders, but the background color of our table leaking out from some "cracks". The reason we see the background color of our table is that the default "cellspacing" attribute of our table is set to "2". We see the background color through these "2-pixel-spaces" between cells. If we set the "cellspacing" attribute to "0", we'll not see through these spaces anymore, so our fake border will be removed. Below is the HTML code for that:
And we'll get a borderless table with two different-color cells:
Sidenote: In order to get around the border problem, we could simply remove the background color for our table (and making it transparent), instead of adding a cellspacing attribute! Like this:
The above HTML code will create the same effect, except that there will still be a 2-pixel-space between the two cells:
Text Background ColorsThe last part of this section of our free online web design course is going to explore how to add a background color to texts. To achieve this effect, we're going to use Cascading Style Sheets (or shortly "CSS"), which we'll cover in much greater depth later on in our online web design course. In order to add a background color to texts, we are going to use the <span> tag and the "style" attribute together. The <span> tag is going to help us determine the starting and ending points of our effect, and the "style" attribute is going to do the actual work of adding a background color. Have a look at the below HTML code to get a clearer picture:
The above HTML code will produce the below output:
The "style" attribute is genereally used as style="property:value". In the above example, our property is "background-color" and our value is "#CCCCFF", which is the hex code of the color I have selected as background color for our text. Sidenote #1: Check out my web design resources page to download a superb eBook! Sidenote #2: If you enjoyed this lesson, please link to it :) We've learned how to add background colors. How about background images? Next lesson of Online Web Design Course is going to teach you how to add background images to your HTML documents!
Nearby Lessons: • Lesson 1-04 Web Colors Unleashed• Lesson 1-05 HTML Tables • Lesson 1-06 Background Alteration • Lesson 1-07 Images • Lesson 1-08 Hyperlinking Back To Top Home | Resources | Articles | Lessons | Directory | Forums Copyright© 2004 Onur Özcan. All Rights Reserved. | Partner Links |