how to change the background color of cells in a table

Status
Not open for further replies.

Troubledyouth

In Runtime
Messages
123
ok here is what i want to do.i am goin to have to cells side by side and i want each one to display a different color so what do i have to put in each <td> tag.i have put bgcolor and color and i can't remember how to do it
 

Emily

Daemon Poster
Messages
1,179
I think you can just put <td bgcolor="#000000"> or whatever color in each one. :confused:
 

bla!!

Daemon Poster
Messages
1,118
Location
/usr/root/mn/us
That should work perfectly.

<td bgcolor="#F1F1F1">

or if you are going to use a standardized color you can do this

<td bgcolor="red">
 

kerriganm

Baseband Member
Messages
57
FYI, I've found some browsers seem to ignore the td bgcolor if you don't actually use the # in front of it. IE lets you get away with leaving it out, but they don't all.
 

jinexile

In Runtime
Messages
260
bgcolor is improper Html, a throwback from pre-CSS times.

These days you want to keep your style and formating seperate.

Code:
<style type="text/css">
td {
Background-Color:#00ff00;
}
</style>

<table>
   <tr>
      <td>This background should be green</td>
   </tr>
</table>
 

kerriganm

Baseband Member
Messages
57
Troubledyouth wanted each td a different color, so that approach wouldn't work for him. He could use inline styles:

<table>
<tr>
<td style="background:blue">blue cell</td>
<td style="background:green">green cell</td>
</tr>
<tr>
<td style="background:yellow">yellow cell</td>
<td style="background:red">red cell</td>
</tr>
</table>
 

jinexile

In Runtime
Messages
260
oops mb.

He could also name them

He could also use ids like this:

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
   <title></title>
   <style type="text/css">
   #row1 {
      Background-Color:#00FF00;
   }
   #row2 {
      Background-Color:#FF0000;
   }
   #row3 {
      Background-Color:#0000FF;
   }
   </style>
</head>
<body>
   <table>
      <tr>
         <td id="row1">This background should be green</td>
         <td id="row2">This background should be red</td>
         <td id="row3">This background should be blue</td>
      </tr>
   </table>
</body>
</html>
 
Status
Not open for further replies.
Top