943,774 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
May 10th, 2009
0

Add a background color to a table

Expand Post »
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...

HTML and CSS Syntax (Toggle Plain Text)
  1. <table cellpadding="15" cellspacing="15">
  2. <tr>
  3. <td>CELL 1</td>
  4. <td>CELL 2</td>
  5. </tr>
  6. <tr>
  7. <td>CELL 3</td>
  8. <td>CELL 4</td>
  9. </tr>
  10. </table>
Similar Threads
Reputation Points: 19
Solved Threads: 115
Nearly a Posting Virtuoso
cguan_77 is offline Offline
1,317 posts
since Apr 2007
May 10th, 2009
0

Re: Add a background color to a table

edit your table to something like

<table cellpadding="15" cellspacing="15" bgcolor="red">
OR with(RGB)

<table cellpadding="15" cellspacing="15" bgcolor="#FF0000">
Last edited by peter_budo; May 14th, 2009 at 6:38 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
affnetguru is offline Offline
5 posts
since Aug 2008
May 10th, 2009
0

Re: Add a background color to a table

That is ancient code. Add a style to the stylesheet instead:

HTML and CSS Syntax (Toggle Plain Text)
  1. table {background-color: #ff0000;}
Reputation Points: 730
Solved Threads: 181
Nearly a Senior Poster
MidiMagic is offline Offline
3,314 posts
since Jan 2007
May 11th, 2009
0

Re: Add a background color to a table

HTML and CSS Syntax (Toggle Plain Text)
  1. 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...:
HTML and CSS Syntax (Toggle Plain Text)
  1. <style type="text/css">
  2. #table1 {background-color: #ff0000;}
  3. </style>
  4.  
  5. <table class="table1" cellpadding="15" cellspacing="15">
Last edited by cguan_77; May 11th, 2009 at 2:21 am.
Reputation Points: 19
Solved Threads: 115
Nearly a Posting Virtuoso
cguan_77 is offline Offline
1,317 posts
since Apr 2007
May 11th, 2009
0

Re: Add a background color to a table

#table1 - means id=table1
so

edit your html to...
<table id="table1" ...>
Reputation Points: 10
Solved Threads: 1
Newbie Poster
affnetguru is offline Offline
5 posts
since Aug 2008
May 11th, 2009
0

Re: Add a background color to a table

if you use
HTML and CSS Syntax (Toggle Plain Text)
  1. table {background-color: #ff0000;}
you don't need to add class or id to your table, it will change all table background to #ff0000
Reputation Points: 10
Solved Threads: 10
Junior Poster in Training
rudevils is offline Offline
80 posts
since Jan 2008
May 11th, 2009
0

Re: Add a background color to a table

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"
Reputation Points: 10
Solved Threads: 2
Newbie Poster
!!underlink!! is offline Offline
10 posts
since May 2009
May 11th, 2009
0

Re: Add a background color to a table

Click to Expand / Collapse  Quote originally posted by rudevils ...
if you use
HTML and CSS Syntax (Toggle Plain Text)
  1. 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...
Reputation Points: 19
Solved Threads: 115
Nearly a Posting Virtuoso
cguan_77 is offline Offline
1,317 posts
since Apr 2007
May 11th, 2009
0

Re: Add a background color to a table

Mmmm thats strange,
HTML and CSS Syntax (Toggle Plain Text)
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Untitled Document</title>
  6. <style>
  7. table {
  8. background: #000000;
  9. }
  10. </style>
  11. </head>
  12.  
  13. <body>
  14. <table width="400" border="0" cellspacing="0" cellpadding="0">
  15. <tr>
  16. <td>&nbsp;</td>
  17. </tr>
  18. </table>
  19. </body>
  20. </html>
Here's my example and its work
Reputation Points: 10
Solved Threads: 10
Junior Poster in Training
rudevils is offline Offline
80 posts
since Jan 2008
May 11th, 2009
0

Re: Add a background color to a table

Thanks for all the help guys...
Thanks rudevils
i think the reason why it's not working
i miss this thing on the header..
HTML and CSS Syntax (Toggle Plain Text)
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
Reputation Points: 19
Solved Threads: 115
Nearly a Posting Virtuoso
cguan_77 is offline Offline
1,317 posts
since Apr 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in HTML and CSS Forum Timeline: Image Preloading not working in IE6!! Only CSS..
Next Thread in HTML and CSS Forum Timeline: Website is zoomed out so big on IE browser





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC