0

hi guys, i have this code..to display a table.. but how to add a background color to a table? any help is greatly appreciated.. thanks...

<table cellpadding="15" cellspacing="15">
<tr>
<td>CELL 1</td>
<td>CELL 2</td>
</tr>
<tr>
<td>CELL 3</td>
<td>CELL 4</td>
</tr>
</table>
5
Contributors
10
Replies
11
Views
9 Years
Discussion Span
Last Post by MidiMagic
0

edit your table to something like <table cellpadding="15" cellspacing="15" bgcolor="red"> OR with(RGB) <table cellpadding="15" cellspacing="15" bgcolor="#FF0000">

0
table {background-color: #ff0000;}

hi MidiMagic, how to call that code to the table..

i used like this but it doesn't work, how to do it? thanks...:

<style type="text/css">
#table1 {background-color: #ff0000;}
</style>

<table class="table1" cellpadding="15" cellspacing="15">
0

if you use

table {background-color: #ff0000;}

you don't need to add class or id to your table, it will change all table background to #ff0000

0

yes please use a stylesheet that was if you need to use it again you can just declare the class again and dont use "red" or "white" use the proper hash code like "#fffffff"

0

if you use

table {background-color: #ff0000;}

you don't need to add class or id to your table, it will change all table background to #ff0000

i've tried it but it doesn't work...

0

Mmmm thats strange,

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>
	table {
		background: #000000;
	}
</style>
</head>

<body>
<table width="400" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html>

Here's my example and its work

0

Two points:

use:

.stylename for a class

#stylename for an id

Note that class can be used on multiple tags, id can not.

The use of width= in the tag causes some browsers to ignore the style. Put the width and border in the style too.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.