Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    Regular Coder
    Join Date
    Aug 2002
    Posts
    433
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Put background color....

    Hi do u know how to add some background color to the cells of a table?

  • #2
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts
    Code:
    th, td {
    background-color: #ff0;
    }
    Like so?

  • #3
    Regular Coder thesmart1's Avatar
    Join Date
    Dec 2005
    Posts
    369
    Thanks
    7
    Thanked 3 Times in 3 Posts
    Code:
    Code:
     
    <table>
    <tr>
    <td bgcolor="#ffffff">
    This is the table cell.  It has a background color of white (ffffff).
    </td>
    </tr>
    </table>
    Put any property tags (like cellspacing, cellpadding, width, or border) in the <table> tag. For the background color, all you need to do is include a bgcolor tag in the <td> tag as shown above.

  • #4
    Senior Coder
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    2,636
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thesmart1 - if we were in the 1990's I'd agree, but bgcolor is not valid anymore...

  • #5
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts
    Quote Originally Posted by thesmart1
    Code:
    Code:
     
    <table>
    <tr>
    <td bgcolor="#ffffff">
    This is the table cell.  It has a background color of white (ffffff).
    </td>
    </tr>
    </table>
    Put any property tags (like cellspacing, cellpadding, width, or border) in the <table> tag. For the background color, all you need to do is include a bgcolor tag in the <td> tag as shown above.
    bgcolor tag? That never existed.

  • #6
    Regular Coder thesmart1's Avatar
    Join Date
    Dec 2005
    Posts
    369
    Thanks
    7
    Thanked 3 Times in 3 Posts
    bgcolor exists, try it! I use it all the time. What's wrong with that?

  • #7
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    bgcolor is still valid just deprecated and yes it does exist. Try validating this.
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    
    </head>
    
    <body>
    <table>
    <tr>
    <td bgcolor="#ffffff">
    This is the table cell.  It has a background color of white (ffffff).
    </td>
    </tr>
    </table>
    </body>
    </html>
    But because of CSS styling should be taken care of by CSS not the html. The whole point of CSS is to seperate style and structure.

  • #8
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Quote Originally Posted by Error 404
    bgcolor tag? That never existed.
    Quote Originally Posted by thesmart1
    bgcolor exists, try it! I use it all the time. What's wrong with that?
    Error404 was trying to subtly point out that bgcolor is not a tag, it's an attribute.

    With all respect, having seen a couple of your recent posts, it seems that your technical advice is some years past its 'best by' date.
    However, now that you're joined a decent web development forum, you'll have the opportunity to see and learn newer, more modern techniques that will help improve your knowledge of modern web development and bring your skills up to date.


    (Believe it or not, this post isn't meant to be patronising.)

  • #9
    New Coder
    Join Date
    Dec 2005
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts
    so just for simple background color what do you use instead of body bgcolor=""

  • #10
    Senior Coder
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    2,636
    Thanks
    0
    Thanked 0 Times in 0 Posts
    so just for simple background color what do you use instead of body bgcolor=""
    body { background: #F00 }

    Please read up on CSS !

  • #11
    New Coder
    Join Date
    Dec 2005
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts
    but if they do the same thing, what does it matter

  • #12
    Senior Coder
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    2,636
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You are using tags and attributes which are very outdated.

    These days you should be seperating style and layout from content.

    An example of why you should be using CSS - http://www.csszengarden.com/

    Learn CSS - http://www.w3schools.com/css/default.asp

  • #13
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Quote Originally Posted by Elgyn
    but if they do the same thing, what does it matter
    It's probably worthwhile for you to read this…
    A List Apart (Feb '01): From Table Hacks to CSS Layout: A Web Designer’s Journey



    Perhaps it's not too late for me to work up the whywebstandards page after all.

  • #14
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts
    Quote Originally Posted by Elgyn
    but if they do the same thing, what does it matter
    bgcolor does not exist under HTML 4.01 Strict, XHTML 1.0 Strict or XHTML 1.1


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •