Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    matthewdoucette.com
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2002
    Posts
    635
    Rep Power
    13

    Question setting table row color with CSS


    I want to set the table row background color (bgcolor) with CSS. What is wrong with my code?

    Code:
    td.blogtitle { bgcolor: 0000ff; }
    
    ...
    
    <td class="blogtitle">
    This doesn't work either:

    Code:
    td.blogtitle { color: 0000ff; }
    ...
    
    <td class="blogtitle">
    Matthew Doucette / Xona.com
  2. #2
  3. This is only a test
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Off the air
    Posts
    2,893
    Rep Power
    153
    td.blogtitle { background: 0000ff; }

    I don't think bgcolor does anything in css, and color sets font color.
  4. #3
  5. No Profile Picture
    matthewdoucette.com
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2002
    Posts
    635
    Rep Power
    13
    Originally posted by Ucht
    td.blogtitle { background: 0000ff; }

    I don't think bgcolor does anything in css, and color sets font color.
    Worked. Thanks. I knew it was simple. I had no idea it used "background", but I should have still tried it.
    Matthew Doucette / Xona.com
  6. #4
  7. |<.+#f@#+.&.|
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2002
    Location
    norway
    Posts
    3,009
    Rep Power
    1224
    remember to use the "#" when using hexadecimal notation,

    ie. background:#0000ff;
  8. #5
  9. No Profile Picture
    matthewdoucette.com
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2002
    Posts
    635
    Rep Power
    13
    Originally posted by Akh
    remember to use the "#" when using hexadecimal notation,

    ie. background:#0000ff;
    Why is that? I never use #. I also never used quotes when declaring anything in HTML, is that bad too?
    Matthew Doucette / Xona.com
  10. #6
  11. |<.+#f@#+.&.|
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2002
    Location
    norway
    Posts
    3,009
    Rep Power
    1224
    the use of # is to define that the color attributes you are using are in hexadecimal form
    http://www.w3.org/TR/REC-CSS2/syndata.html#color-units

    in xhtml you always have to quote the attributes
    you are using,
    http://www.w3.org/TR/xhtml1/#h-4.4
  12. #7
  13. No Profile Picture
    matthewdoucette.com
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2002
    Posts
    635
    Rep Power
    13
    If you look at http://www.w3.org/TR/REC-CSS2/syndata.html#color-units you will see that there is not other possible interpretation if you do not use the "#" sign... so most browsers probably default to the proper hexadecimal parsing.
    Matthew Doucette / Xona.com
  14. #8
  15. No Profile Picture
    matthewdoucette.com
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2002
    Posts
    635
    Rep Power
    13
    Check this out about empty elements:

    http://www.w3.org/TR/xhtml1/#guidelines

    C.2. Empty Elements
    Include a space before the trailing / and > of empty elements, e.g. <br />, <hr /> and <img src="karen.jpg" alt="Karen" />. Also, use the minimized tag syntax for empty elements, e.g. <br />, as the alternative syntax <br></br> allowed by XML gives uncertain results in many existing user agents
    These guidelines are almost never followed.
    Matthew Doucette / Xona.com
  16. #9
  17. |<.+#f@#+.&.|
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2002
    Location
    norway
    Posts
    3,009
    Rep Power
    1224
    so most browsers probably default to the proper hexadecimal parsing.
    but you can't be sure of that so,
    therefor one should always specify.

    its just the same as setting width:100; to
    an element, some browsers might parces that
    as 100px, but most wont (as they should)
    so you can't always relay on the browsers,
  18. #10
  19. :(){ :|:&};:
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Germany
    Posts
    297
    Rep Power
    11
    But guidelines are created so that you obey them - and if you want to produce clean code I think you should obey them. Even if nobody else does I see this just as a work that I do to make my code easier to read and understand. I understand it if you don't know that guidelines that you then wouldn't obey them. But as you know them you should use them. And it isn't to hard to add a # or a / - or? At least I try to add them where necessary as long as I remember it
    regards >_<

    ws. fgeller.de
    em. felix@fgeller.de
  20. #11
  21. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Vancouver
    Posts
    7
    Rep Power
    0

    setting the background color of a table row


    I was interested in the response to the person who wanted to set the background color of a table row. To my way of thinking however the response only applied to setting the background color of an individual cell.

    What is the syntax for setting the color for the whole row without dealing with each cell individually

    I tried the following without success

    tr.special {background #000080;}


    <tr class="special">

    Can someone help me out?
  22. #12
  23. This is only a test
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Off the air
    Posts
    2,893
    Rep Power
    153
    Make sure you have a colon between background and your color:

    {background: #000080;}
  24. #13
  25. No Profile Picture
    matthewdoucette.com
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2002
    Posts
    635
    Rep Power
    13

    Re: setting the background color of a table row


    Originally posted by gupps
    I was interested in the response to the person who wanted to set the background color of a table row. To my way of thinking however the response only applied to setting the background color of an individual cell.

    What is the syntax for setting the color for the whole row without dealing with each cell individually

    I tried the following without success

    tr.special {background #000080;}


    <tr class="special">

    Can someone help me out?
    Good point. You can not see it from my code, but in my table my row only had one cell so I decided to change just the cell (or just the "td"). Just use the code that works and replace "td" with "tr" like Ucht said.
    Matthew Doucette / Xona.com
  26. #14
  27. No Profile Picture
    matthewdoucette.com
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2002
    Posts
    635
    Rep Power
    13
    Akh and fgeller, I agree. I am going to go add "#" to all my colors and start quoting variable initializations. It does make sense to stick with what you know is proper.
    Matthew Doucette / Xona.com
  28. #15
  29. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Vancouver
    Posts
    7
    Rep Power
    0

    Re: Re: setting the background color of a table row


    Originally posted by Doucette
    Good point. You can not see it from my code, but in my table my row only had one cell so I decided to change just the cell (or just the "td"). Just use the code that works and replace "td" with "tr" like Ucht said.
    Thanks for the reply. However I still couldnt get it to work so I decided to just use just straight html <tr bgcolor="#000080">
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo