【发布时间】:2016-11-06 18:37:50
【问题描述】:
我有一个如下所示的表格:
<table class="table table-striped table-hover table-responsive" id="commenttable">
<thead>
<th>Status</th>
<th>Subject</th>
<th>Message</th>
<th>Tech</th>
<th>Emailed?</th>
<th>Date/Time</th>
</thead>
<tbody>
<?php
foreach($commresult as $row)
{
if($row['commentPrivate'] == 'yes'){
echo "<tr class='private'>";
}
else{
echo "<tr>";
}
echo "<td>" . ucwords($row['commentType']) . "</td>";
echo "<td>" . ucwords($row['commentSubject']) . "</a></td>";
echo "<td>" . $row['commentMessage'] . "</td>";
echo "<td>" . ucwords($row['commentBy']) . "</td>";
echo "<td>" . ucwords($row['commentEmailComm']) . "</td>";
echo "<td>" . $row['commentDate'] . "</td>";
echo "</tr>";
}
?>
</tbody>
我想要做的是if $row['commentPrivate'] == 'yes' 我想将那一行的背景颜色更改为红色。
我试过只使用<tr bgcolor="#ff7f7f">,但没有用。所以现在我只是试图将“私人”类添加到该行并使用CSS 定位它,我认为我失败了。
这是CSS:
.private {
background-color: #ff7f7f;
}
我也试过了:
#commenttable tbody .private {
background-color: #ff7f7f;
}
感谢任何帮助。
【问题讨论】:
-
试试这个
#commenttable tbody tr .private { background-color: #ff7f7f; } -
那行不通。我回应了 $row['commentPrivate'] 结果,它确实是“是”
-
您检查控制台是否有任何错误?或者可能是 CSS 被其他一些 CSS 覆盖了?
-
我在控制台中看不到任何错误。我唯一拥有的其他 CSS 是用于填充表格数据,仅此而已。
-
bootstraps table-striped 不应该覆盖它
标签: php html css background-color