我有一张这样的桌子:

<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'。所以现在我只是试图将类“private”添加到行中,并使用<tr bgcolor="#ff7f7f">将其作为目标,我认为这是非常糟糕的。
这里是css:
.private {
background-color: #ff7f7f;
}

我也试过:
#commenttable tbody .private {
background-color: #ff7f7f;
}

如有任何帮助,我们将不胜感激。

最佳答案

.table-striped类将斑马条纹添加到表中。因此,为了重写相同的内容,您可以在CSS中使用:

.private {
  background-color: #ff7f7f !important;
 }

这里有一个Demo
!important.table .table-striped更具体。因此,适用于.private的规则。
php - 使用CSS定位表中具有ID的特定类-更改ROW背景-LMLPHP
因此,您可以使用.table-striped来重写同样的内容。
附加css属性值的!important值是自动获胜。它甚至覆盖标记中的内联样式。唯一的办法!重要的值可以被另一个重写!稍后在css中声明的重要规则,否则具有相等或很大的特定值。

07-28 02:26
查看更多