Adding background to the rows/cols of a simple table

liunx

Guest
Now, below is my code for creating a small and simple table with rows and columns :<br />
<br />
<HTML><br />
<BODY><br />
<TABLE BORDER=1><br />
<br />
<tr><br />
<td><b>Name</b></td><br />
<td><b>Notes</b></td></tr><br />
<br />
<tr><br />
<td>Abraham Lincoln</td><br />
<td>Honest Abe : The Best</td><br />
</tr><br />
<br />
<tr><br />
<td>Franklin D' Roosevelt</td><br />
<td>Did a lot for America</td><br />
</tr><br />
<br />
<tr><br />
<td>George Washington</td><br />
<td>The Father of all Presidents</td><br />
</tr><br />
<br />
<tr><br />
<td>Ronald Reagan</td><br />
<td>A nice President for America</td><br />
</tr><br />
<br />
<tr><br />
<td>Jimmy Carter</td><br />
<td>Peace-loving man. Won the Nobel Peace Award.</td><br />
</tr><br />
<br />
<tr><br />
<td>George W. Bush</td><br />
<td>Err....for him...I've no comments.</td><br />
</tr><br />
<br />
</TABLE><br />
</BODY><br />
</HTML><br />
<br />
<br />
If you copy, paste and view the code in a HTML file and view it in a browser, you'll see a table with several rows and 2 columns.<br />
<br />
My questions are :<br />
<br />
1) How do I make the background of the first row(Name, Notes) a different color other than white?<br />
For example, I want grey to be the background color for the 1st row.<br />
<br />
2) As you can see, the borders of this table is kind of indented and sunken. How do I make it totally flat, with just a 1 pixel flat black border?<br />
<br />
Thanks! :):)<!--content-->In order to change the background color of either a row, or a cell, you can do this:<br />
<br />
<tr style="background-color: green"><br />
<br />
or you can do the same thing for the individual table cells if you don't want the whole row that color.<br />
<br />
And for your second question, you want to do is change the border color/width? This can be done using the same method as above:<br />
<br />
style="border-width: 1px; border-color: black"<br />
<br />
Hope that's what your looking for:).<!--content-->Thanks a lot, Daerus! :):):)<br />
<br />
The only problem now is that the border thing doesn't seem to show up.<br />
<br />
I coded :<br />
<br />
<HTML><br />
<BODY><br />
<TABLE><br />
<tr style="border-width: 1px; border-color: black"><br />
<td><b>Name</b></td><br />
<td><b>Notes</b></td><br />
</tr><br />
<br />
<tr style="background-color: green"><br />
<td>Abraham Lincoln</td><br />
<td>Honest Abe : The Best</td><br />
</tr><br />
<br />
</TABLE><br />
</BODY><br />
</HTML><br />
<br />
1) But there isn't any border! :eek: I'm sure I coded wrongly somewhere.<br />
<br />
2) Lastly, regarding :<br />
<br />
<tr style="background-color: green"><br />
<br />
Can I specify a custom color like light blue? I tried replacing 'green' with #000FFC but there seems to be no effect.<br />
<br />
Please pardon me for my total foolishness and unchallenged stupidity. Thanks! :):)<!--content-->Hey there, glad I could help you a bit Xeon:).<br />
<br />
Now let's see.. the border thing.. did you want a border around every table cell/row(just as it appears with border="1" only in a different color?)?<br />
<br />
If that's what your looking for, I guess you could just go like so:<br />
<br />
<table border="1" bordercolor="black"><br />
<br />
The style="border-width: 1px; border-color: black" should go in the <table> tag, but maybe this wasn't what you were looking for, this would put a single border around the whole table(not through-out it, if that makes sense).<br />
<br />
Now about the color thing.. the color you chose (#000FFC) would not be considered a 'web safe' color(according to photoshop:)), which is why I suspect that it doesn't work with your tables. If you have a program like Photoshop(what I use), or maybe Paint Shop Pro can do this as well.. but they can show you which colors are 'web safe', or if your choosing a color that isn't. Maybe try this one: 0000FF instead of your other one.<br />
<br />
Hope this helps :).<!--content-->From Daerus:<br />
<br />
Now let's see.. the border thing.. did you want a border around every table cell/row(just as it appears with border="1" only in a different color?)?<br />
<br />
If that's what your looking for, I guess you could just go like so:<br />
<br />
<table border="1" bordercolor="black"><br />
<br />
The style="border-width: 1px; border-color: black" should go in the <table> tag, but maybe this wasn't what you were looking for, this would put a single border around the whole table(not through-out it, if that makes sense).<br />
<br />
Hi there and thanks a lot, Daerus! Things are much closer to what I want now, although it's still not exactly the same.<br />
I've attached a screenshot to this post to illustrate the border I need. :):)<br />
<br />
The code you gave me draws a flat black border around the table, and that's good! :)<br />
But it also draws borders around each cell.<br />
<br />
Thanks, Daerus! U rule! :D<br />
Xeon!<!--content-->Ah, ok. I see what you need. This is easily done with the cellspacing and cellpadding tags. Add this to the <table> tag:<br />
<br />
cellspacing="0" cellpadding="0"<br />
<br />
This will set the table spacing and padding between each of the cells/rows to 0 (if you don't specify the cellspacing or padding, it will be a default of 3 I believe). That should get you the result that you want.<br />
<br />
Feel free to ask if you have any other questions:).<!--content-->From Daerus:<br />
<br />
Ah, ok. I see what you need. This is easily done with the cellspacing and cellpadding tags. Add this to the <table> tag:<br />
cellspacing="0" cellpadding="0"<br />
This will set the table spacing and padding between each of the cells/rows to 0 (if you don't specify the cellspacing or padding, it will be a default of 3 I believe). That should get you the result that you want.<br />
Feel free to ask if you have any other questions<br />
<br />
Thanks a lot, Daerus! It's much much better than before, and everything looks fine. The only thing left is that the style of the border seems to be kinda "raised"/embossed, and the kind of border I want is a flat, single line, like when you draw on a paper with a ruler and a pencil : the kinda flat, 1 line border. :)<br />
<br />
I remember seeing this kinda border before, but if it requires time and lots of thinking, then I guess you can forget about it. :)<br />
<br />
Thanks, Daerus! :)<br />
Xeon.<!--content-->hey Xeon :)!<br />
<br />
you can also make a background image using Background, I believe!<!--content-->Hi there MorrowWasted! :)<br />
How have you been? U really should participate more in the CodeGuru forums. :D:D:):D<!--content-->
 
Back
Top