Add a background color to a table

Thread Solved

Join Date: Apr 2007
Posts: 1,098
Reputation: cguan_77 has a little shameless behaviour in the past 
Solved Threads: 91
cguan_77's Avatar
cguan_77 cguan_77 is offline Offline
Veteran Poster

Add a background color to a table

 
0
  #1
May 10th, 2009
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>
TRY MY SUGGESTIONS AT YOUR OWN RISK
Do other alternative first..cheap and easy ways..
Don't take out money from your pocket when you're not so sure that it will solve the problem..
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 5
Reputation: affnetguru is an unknown quantity at this point 
Solved Threads: 1
affnetguru affnetguru is offline Offline
Newbie Poster

Re: Add a background color to a table

 
0
  #2
May 10th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 3,203
Reputation: MidiMagic has a spectacular aura about MidiMagic has a spectacular aura about 
Solved Threads: 164
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Nearly a Senior Poster

Re: Add a background color to a table

 
0
  #3
May 10th, 2009
That is ancient code. Add a style to the stylesheet instead:

HTML and CSS Syntax (Toggle Plain Text)
  1. table {background-color: #ff0000;}
Daylight-saving time uses more gasoline
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 1,098
Reputation: cguan_77 has a little shameless behaviour in the past 
Solved Threads: 91
cguan_77's Avatar
cguan_77 cguan_77 is offline Offline
Veteran Poster

Re: Add a background color to a table

 
0
  #4
May 11th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 5
Reputation: affnetguru is an unknown quantity at this point 
Solved Threads: 1
affnetguru affnetguru is offline Offline
Newbie Poster

Re: Add a background color to a table

 
0
  #5
May 11th, 2009
#table1 - means id=table1
so

edit your html to...
<table id="table1" ...>
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 79
Reputation: rudevils is an unknown quantity at this point 
Solved Threads: 9
rudevils rudevils is offline Offline
Junior Poster in Training

Re: Add a background color to a table

 
0
  #6
May 11th, 2009
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
If love is blind, why there's a bikini ??

Post your article at Bali Side Notes share your knowledge
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 10
Reputation: !!underlink!! is an unknown quantity at this point 
Solved Threads: 2
!!underlink!! !!underlink!! is offline Offline
Newbie Poster

Re: Add a background color to a table

 
0
  #7
May 11th, 2009
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"
Printed Lanyards at Lanyardpass.co.uk
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 1,098
Reputation: cguan_77 has a little shameless behaviour in the past 
Solved Threads: 91
cguan_77's Avatar
cguan_77 cguan_77 is offline Offline
Veteran Poster

Re: Add a background color to a table

 
0
  #8
May 11th, 2009
Originally Posted by rudevils View Post
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...
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 79
Reputation: rudevils is an unknown quantity at this point 
Solved Threads: 9
rudevils rudevils is offline Offline
Junior Poster in Training

Re: Add a background color to a table

 
0
  #9
May 11th, 2009
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
If love is blind, why there's a bikini ??

Post your article at Bali Side Notes share your knowledge
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 1,098
Reputation: cguan_77 has a little shameless behaviour in the past 
Solved Threads: 91
cguan_77's Avatar
cguan_77 cguan_77 is offline Offline
Veteran Poster

Re: Add a background color to a table

 
0
  #10
May 11th, 2009
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">
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC