如何在列中的每个第三个元素上强加唯一的样式属性? [关闭]

I am new to this site but I need help. I have successfully displayed records from and database with php. The records displays nicely with a CSS class. But what I really want is to change the class name after every three record display. In other words, three records will be display with the same css class name like (column) but the fourth record will use a difference class name like(column-last). Can someone please help me with this?

You can use CSS3's nth-child selector to selectively do so. For eg. let's say you are applying class myClass to the records. Now, add the following to CSS:

.myClass:nth-child(4n) {
    // Your new properties
}

If you don't want to use css 3 you can use a modulus 3 condition when you loop through your rows

$classname="row1and2";
for ($rowcount=0;$rowcount < $maxrow;$rowcount++){
$classname=($rowcount%3==0)?"row3":"row1and2";
<?php echo "<tr class=$classname><td>values...</td></tr>?>
}

obviously this is just simple example.