No te hace falta PHP, te basta con hacerlo con CSS usando
nth-child()
:
Código CSS:
Ver original.fondo_caja:nth-child(3n+1) {
background: firebrick;
}
.fondo_caja:nth-child(3n+2) {
background: green;
}
.fondo_caja:nth-child(3n+3) {
background: purple;
}
También puedes usar
nth-of-type()
si el contenedor padre contiene otros elementos que no sean
div.fondo_caja
.