Chris Paton Chris Paton - 5 months ago 31
CSS Question


I'm just having a play around with a basic table with input from a form on another page.

I want to change the CSS of table in depending on the result of the game.

If the home team wins I want the background colour of the row to be gree if they loose then red, otherwise remain the same.

So I figured I'd need to use IF and ELSES, however not quite sure how to integrate that with CSS and where to put it.

I'm still very new with PHP.

<title>Player Stats</title>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;

td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;

tr:nth-child(even) {
background-color: #dddddd;


<h1>Player Stats</h1><br>

<th>Home team</th>
<th>Away team</th>
<td><?php echo $_POST["home"]; ?></td>
<td><?php echo $_POST["away"]; ?></td>
<td><?php echo $_POST["goalsh"]; ?> - <?php echo $_POST["goalsa"]; ?></td>
<td><?php echo $_POST["formGender"]; ?></td>


<a href="">Update player stats</a>


One way would be to make two classes, red and green.

.red{ background-color: red }
.green{ background-color: green } 

You could do something like,

<tr class="<?= (!($_POST["goalsa"] > $_POST["goalsh"])) ? 'green' : (($_POST["goalsa"] > $_POST["goalsh"])? 'red' : '') ?>" />