Jump to content

Alternating Column Colors?


lu13cky

Recommended Posts

probably in the same way people do rows. assign classes to <td>'s based on an odd or even iterator value (assuming you are doing it in a loop).

Link to comment
Share on other sites

probably in the same way people do rows. assign classes to <td>'s based on an odd or even iterator value (assuming you are doing it in a loop).
yeah I've attempted it...annnnd it just turns my columns into rows.hah. I'll mess around with my code a bit more I guess to achieve it.
Link to comment
Share on other sites

If you're columns are turning themselves into rows, then it sounds like your table is being outputted incorrectly.

Link to comment
Share on other sites

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title><script type="text/javascript">/*<![CDATA[*//*---->*//*--*//*]]>*/</script> <style type="text/css">table.mytable {margin:0 auto;}.tdcol1, .tdcol2 {width:100px; text-align:center;}.tdcol1 {background-color:#CCFFCC;}.tdcol2 {background-color:#FFFF99;}</style></head><body><?php$tdcount=4;$trcount=4;?><table cellpadding="0" cellspacing="0" border="1" class="mytable"><?phpfor($i=0;$i<$trcount;$i++){echo '<tr>';for($j=0;$j<$tdcount;$j++){if($j%2==0){$tdcol="tdcol1";}else{$tdcol="tdcol2";}echo '<td class="'.$tdcol.'">'.($j+1).'</td>';}echo '</tr>';}?></table></body></html>

Link to comment
Share on other sites

<script type="text/javascript">/*<![CDATA[*//*---->*//*--*//*]]>*/</script>
I keep seeing this in all the threads you reply and I'm confused. Could you explain what it's for?
Link to comment
Share on other sites

I keep seeing this in all the threads you reply and I'm confused. Could you explain what it's for?
I've never seen it like that, but I use something similar to tell the w3 validator to ignore my java script:<script type='text/javascript'>//<![CDATA[//]]></script>Without that, the w3 validator complains about < and > anywhere in the script, ie if (aVariable<anotherVariable) {
Link to comment
Share on other sites

It's not necessarily wrong to have that there, that page is talking about doing that to "hide" the Javascript code from an XML parser if your page is served as XHTML or XML+HTML. There's another discussion about it here:http://javascript.about.com/library/blxhtml.htmIt's probably not necessary to include all of the extra comments around it though, several sites like that talk about doing that to support "older" web browsers, but the fact is that in these days no one uses a browser that doesn't understand what you're trying to do. Even IE6 should support a normal cdata tag, so it's probably not necessary to hide it with Javascript comments.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...