CSS - 将条件样式应用于表行

时间:2017-11-16 13:34:07

标签: html css css3

我有一个要求,我必须为我的表行应用条件样式,但样式永远不会被应用。

.test1 {
  background-color: '#ffbf00';
}
.test2 {
  background-color: '#92D050';
}
.test3 {
  background-color: ' ';
}
<table id="testTable">
  <tr styleClass="test1">
    <td></td>
    <td></td>
  </tr>
</table>

但样式永远不会应用。我错过了什么?

4 个答案:

答案 0 :(得分:2)

老兄你在这个简单的HTML代码中有10个错误。请学习HTML和CSS!以下是您可能希望以正确的方式实现的目标。

&#13;
&#13;
.test1 {
  background-color: #ffbf00;
}
.test2 {
  background-color: #92D050;
}
.test3 {
  background-color: transparent;
}
&#13;
<table id="testTable">
  <tr class="test1">
    <td>a</td>
    <td>b</td>
  </tr>
</table>
&#13;
&#13;
&#13;

不要在颜色上加注。它意味着类,而不是styleClass。 &#39; &#39;不是有效的颜色值。等等......

答案 1 :(得分:1)

使用HTML中的定义类,不要在十六进制值周围使用引号。

&#13;
&#13;
.test1 {
  background-color: #ffbf00;
}
.test2 {
  background-color: #92D050;
}
.test3 {
  background-color: ' ';
}
&#13;
<table id="testTable">
  <tr class="test1">
    <td>Test</td>
    <td>Test</td>
  </tr>
</table>
&#13;
&#13;
&#13;

答案 2 :(得分:0)

定位到Update(draftTask, "Cost", "500");

td

答案 3 :(得分:0)

你需要添加类名和 styleClass =&#34; test1&#34; 不正确的语法

所以更新

styleClass="test1"

class="test1"

还有一件事你的风格代码并不完美 所以也要更新

background-color: '#92D050';

background-color: #92D050;

因为这也是语法错误 其他代码还可以

&#13;
&#13;
  .test1 {
        background-color: #ffbf00;
    }
    .test2  {
        background-color: #92D050;
    }
    .test3  {
        background-color: rebeccapurple;
    }
&#13;
<table id="testTable">
    <tr class="test1">
        <td>test1</td>
        <td>test1</td>
    </tr>
    <tr class="test2">
        <td>test2</td>
        <td>test3</td>
    </tr>
    <tr class="test3">
        <td>test4</td>
        <td>test5</td>
    </tr>
</table>
&#13;
&#13;
&#13;