I have 14 hex colors I want to alternate as background color.
How would I do that? And I also want to avoid getting the same color twice in a row.
Let's say I have the colours: blue, red, yellow, black, pink, white
I wouldn't want yellow, black, black, black, blue, white, white.....
Could someone show me in the right direction.
<?php
foreach($db->query("SELECT * FROM custom WHERE id = $id") as $row):
?>
<tr bgcolor="#C6A511">
<td colspan="25"><?=$row['a']?></td>
<td colspan="8"><div style="width:50px; background:ONE-OF-THE-14-BACKGROUND-COLORS-HERE"> </div> </td>
<td colspan="8"><?=$row['c']?></td>
</tr>
For a pure CSS route you might like to look at the :nth-child
pseudo-class.
A good overview on how the selector and associated equations work on CSS Tricks
<?php
$rownum = 0;
foreach($db->query("SELECT * FROM custom WHERE id = $id") as $row):
?>
<tr bgcolor="#C6A511">
<td colspan="25"><?=$row['a']?></td>
<td colspan="8"><div style="width:50px" class="bg<?php echo ($rownum++) % 14; ?>"> </div> </td>
<td colspan="8"><?=$row['c']?></td>
</tr>
Don't forget to create the bg0..13
classes in CSS.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.