Simple Machines Community Forum

General Community => Scripting Help => Topic started by: ArrayInteractive on March 11, 2013, 01:34:36 PM

Title: Alternating row colours for topics
Post by: ArrayInteractive on March 11, 2013, 01:34:36 PM
Wondering if anyone has an 'easy' way of doing this in 2.0.2

I would like to be able to alternate the colour backgrounds for each topic line.
ie: topic 1: bg=#000
     topic 2: bg=#FFF
     topic 3: bg=#000
     topic 4: bg=#FFF

It seems like I would need to find the loop that writes the <tr> tag and add an odd/even loop that adds a class to the< tr class="odd"> when it writes it. Then add some CSS for those new classes.

Just wanted to check if there was an already prescribed method, or if someone could point me to that <tr> function.

Thanks.
Title: Re: Alternating row colours for topics
Post by: Arantor on March 11, 2013, 01:44:12 PM
It's in the depths of your theme's MessageIndex.template.php, inside a foreach() covering... $context['topics'] I think it is.
Title: Re: Alternating row colours for topics
Post by: ArrayInteractive on March 11, 2013, 01:55:02 PM
Will check it out. Thanks.
Title: Re: Alternating row colours for topics
Post by: ArrayInteractive on March 11, 2013, 03:25:07 PM
For reference, it's actually the <td>'s that would need to be styled for each row not the <tr>'s.
Title: Re: Alternating row colours for topics
Post by: Arantor on March 11, 2013, 03:28:12 PM
For reference, you can attach a style to the tr's provided that the td itself doesn't replace it.

There are times I've set the entire tr to windowbg or windowbg2 without setting a style per td ;)
Title: Re: Alternating row colours for topics
Post by: ArrayInteractive on March 11, 2013, 09:00:34 PM
Ahh nice, I haven't tried that in a long time. Seems like at least once upon a time, TR styling was not supported in all browsers. I believe it may have been an IE6 thing. Anyway I'll give it a go.

Title: Re: Alternating row colours for topics
Post by: MrPhil on March 12, 2013, 09:40:03 AM
I think I've seen tr styling problems and limitations even in modern browsers. It's a tricky area, as <tr>s themselves don't display anything. However, you can see if properties are inherited by and from <tr>s.