• Log in or sign up for an account here: https://www.sythe.org/login

Help me understand a pretty basic concept

1994RANGERS

Forum Addict

Banned
Joined
May 22, 2010
Sythe Gold
0
Messages
532
Location
Jersey<3
Im currently in a computer science class. So far we've learned html which is pretty basic and easy. We just started css. I missed a couple days so I don't really know what I'm doing.

Im working on a project. Were making a pretty complex table.How would I make cells in the same row different colors with css?
I know how to do it in html but with css its confusing me.
Code:
<html>
<head>
<style type="text/css">
body {background-color:black;}
body {color:white;}
body {font-family:"arial";}
table
{
width:100%;
}
td
{
background-color:green;
}

</style>
</head>



<table>
<tr>
<td><img src="http://buildingabrandonline.com/wp-content/uploads/2010/08/music-notes1.jpg" height="75" width="75"></img></td>
<td><img src="http://www.theinsidersband.com/files/SamAshLogo.jpg" height="75" width="75"></img></td>
<td><img src="http://www.bandsquare.com/blog/wp-content/uploads/Electric_Guitar.jpg" height="75" width=75"></img></td>
</tr>
</table>


</html>

To clarify I'm trying to make the first td green. And the second td orange. And the third td blue. How would I do this? Whenever I do this is just automatically makes the whole row one color
 
You could assign each td its own class or use inline styling.

A (assigning a class or id):

td.green {
background-color: green;
}

td.orange {
background-color: orange;
}

etc etc etc.

OR

B (inline styling):

<td style="background-color: green;"></td>
<td style="background-color: orange;"></td>

If you need anymore help, let me know.
 
What do you mean assign a class or id?


Change your <td> into <td class = "green">...</td>

So now when you do

Code:
td.green {
     background-color: green;
}

in your CSS, then that "class" will have a background color of green, compared to say <td class = "orange">...</td>

Code:
td.green {
     background-color: orange;
}


edit: There really are quite a few ways of doing this, but for CSS this is the most organized.
 
CORRECT
You could assign each td its own class or use inline styling.

A (assigning a class or id):

td.green {
background-color: green;
}

td.orange {
background-color: orange;
}

etc etc etc.

OR

B (inline styling):

<td style="background-color: green;"></td>
<td style="background-color: orange;"></td>

If you need anymore help, let me know.
 
Runescape Gamblingrunescape gambling
Back
Top