tags:

views:

90

answers:

4

The following is a class which I use to highlight a row, but it only makes changes for the cursor and font, not bgcolor of a row.

I have also used background-color: #FFDC87; but it fails to get the desired output.

.highlighted {

    bgcolor: #FFDC87;
    cursor          : pointer;
    /*font-size : 50px;*/
}

How can I make it work?

+9  A: 

That's because the bgcolor CSS property doesn't exist. The property you're looking for is background-color.

If this doesn't work, there's something else that is messing with the element's background-color, and is blocking this from working. But we'll need a little more code to help you with that.

Douwe Maan
There's always `!important` to save the day. http://www.w3.org/TR/CSS2/cascade.html#important-rules
badp
No offense, but the OP missed the obvious `bgcolor`... IMO he shouldn't be exposed to !important just yet.
chakrit
+3  A: 

Instead of bgcolor, the CSS rule is background-color. Give that a try.

wsanville
+2  A: 

The CSS for background color is "background-color", e.g. background-color: #FFDC87;

Try that :)

Jake Worrell
+5  A: 

As is clear by the other answers, it's background-color instead of bgcolor. Note that you can see if there are errors in your HTML, JS or CSS code if you're using a plug-in like Firebug or Webdeveloper (both Firefox plug-ins). This is what Webdeveloper mentioned:

alt text

And you'll probably also want to make the table's borders collapse, otherwise the rows in your table will have gaps in it. Here's what you could do:

<html>
  <head>
    <style>
      table {
        border-collapse: collapse;
      }
      td {
        padding-right: 10px;
      }
      .highlighted {
        background-color: #ffdc87;
        cursor: pointer;
      }
    </style>
  </head>
  <body>
    <table>
      <tr class="highlighted">
        <td>1</td><td>11</td><td>111</td>
      </tr>
      <tr>
        <td>2</td><td>22</td><td>222</td>
      </tr>
      <tr class="highlighted">
        <td>3</td><td>33</td><td>333</td>
      </tr>
      <tr>
        <td>4</td><td>44</td><td>444</td>
      </tr>
      <tr class="highlighted">
        <td>5</td><td>55</td><td>555</td>
      </tr>
    </table>
  </body>
</html>
Bart Kiers