Forum Moderators: not2easy
I know you still have to add the class to each row but I can't think of another way to have different properties for alternating rows.
I hope this helps.
.listfont {
font-family: Verdana, Arial, Helvetica;
font-size: 11px;
font-weight: normal;
background-color: #CCCCFF;
color: black;
text-align: left;
margin-top: 0;
margin-bottom: 0;
}
.listfont2{
font-family: Verdana, Arial, Helvetica;
font-size: 11px;
font-weight: normal;
background-color: #FFFFCC;
color: black;
text-align: left;
margin-top: 0;
margin-bottom: 0;
}
The guestbook is generated via script - when you choose to view, each name/comment is placed in a table data cell/row of it's own, the script gives even numbered records one class, odd numbered records the other class. Thus every other record is a different color. So, it can even be done by automatically generated tables.
You could use scripting to detect whether it's even/odd, I'm not a big scripter so someone else may help you out there.
<added>Ok, here we go!
[w3.org...]
Examples:
tr:nth-child(2n+1) /* represents every odd row of a HTML table */
tr:nth-child(odd) /* same */
tr:nth-child(2n) /* represents every even row of a HTML table */
tr:nth-child(even) /* same *//* Alternate paragraph colours in CSS */
p:nth-child(4n+1) { color: navy; }
p:nth-child(4n+2) { color: green; }
p:nth-child(4n+3) { color: maroon; }
p:nth-child(4n+4) { color: purple; }
It's CSS3, but there's a solution for it! :)
Doesn't work in IE though.</added>
<table border="1">
<?php
$row = 25;
$x = 1;while ($x <= $row) {
if($x%2): $color = "#FFFFFF"; else: $color = "#CCCCCC"; endif;
print "<tr><td style=\"background-color: ".$color."\">Row #".$x."</td></tr>\n";
$x++;
}
?>
</table>
hth
The downside is that this only works in recent versions of IE, not in Netscape or Opera at all. (The PRO version -for $29- improves on this, and adds other features, chiefly the ability to resort columns.)
<script language="JavaScript">
<!--
var table = document.getElementById('tabbed');
var allTRs = table.getElementsByTagName("tr");
for (i=1; i <= allTRs.length ; i++) {
if (i % 2 == 1)
allTRs[i].style.backgroundColor = "#eeeeee";
}
-->
</script>
Thanks, guys!
There is a way you can use CSS to "do stuff" to every nth element......It's CSS3, but there's a solution for it!
Doesn't work in IE though
That is pretty cool. Too bad it will be 5 years before we can use it. Its amazing how fast things evolve in the computer industry but then you compare that to how slow things evolve in the web development dept :(.
<table class="rows">
<tr><td>...
<tr class=e><td>...
<tr><td>...
<tr class=e><td>...
...
</table>
.rows tr { background: #ccc } /* selectivity of 0-1-1 */
.rows .e { background: #fff } /* selectivity of 0-2-1 */
Now you've saved at least 7 * the number of rows bytes in your HTML. Probably more since you'll use friendly names like class="other".
Furthermore, you can specify only the overrides in the odd row, cutting down on bloat in your style sheet.
Combined with the :nth-child() selector mentioned by DrDoc, you get:
.rows tr { /* defaults */ }
.rows tr:nth-child(even) { /* overrides */ }
With no additional classes on your tr elements, saving at least 14 * the number of rows bytes!