我有一个看起来像这样的表:
<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>
我想要做的是如果$row [‘commentPrivate’] ==’是’我想将该行的背景颜色更改为红色.
我尝试过使用< tr bgcolor =“#ff7f7f”>这没用.所以现在我只是尝试将类’private’添加到行中并使用CSS定位它,我认为我失败了.
这是css:
.private {
background-color: #ff7f7f;
}
我也尝试过:
#commenttable tbody .private {
background-color: #ff7f7f;
}
任何帮助表示赞赏.
解决方法:
.table-striped类将斑马条纹添加到表中.所以要覆盖相同的内容,你可以像这样在你的CSS中放置!important:
.private {
background-color: #ff7f7f !important;
}
这是一个Demo
.table .table-striped比.private更具体.因此,.table-striped的规则占优势.
所以,你可以使用!important来覆盖它.
附加CSS属性值的!important值是自动获胜.它甚至覆盖了标记中的内联样式.可以覆盖!important值的唯一方法是使用CSS中稍后声明的另一个重要规则,否则具有相同或更大的特异性值.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。