Welcome to WebmasterWorld Guest from 18.205.176.100

Forum Moderators: not2easy

Message Too Old, No Replies

Odd and even

alternating odd and even ids

     
10:41 pm on Apr 6, 2017 (gmt 0)

Full Member from GB 

10+ Year Member

joined:May 20, 2003
posts: 274
votes: 0


I wonder if it is possible either by just css, or css backed up by javascript or something, to have alternating background colours for message ids on a dynamic page.

It's for a modification of SMF that has nothing to distinguish each reply other than a generated message id (#msg2, #msg3, #msg4 and so on) which I can create a rule for. I suppose I could create a stylesheet with like a gazillion rules for every numbered reply, but I wondered if I could create an odd and even system that would mean only 2 rules.

in other words, rather than doing this:

#msg1
{
background-color: #999;
}
#msg2
{
background-color: #666;
}
#msg3
{
background-color: #999;
}
#msg4
{
background-color: #666;
}

can I do something along the lines of:

#msg(odd)
{
background-color: #999;
}
#msg(even)
{
background-color: #666;
}

?

Any help would be deeply appreciated.
11:16 pm on Apr 6, 2017 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member tangor is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Nov 29, 2005
posts:10125
votes: 1007


If using table the following works great:

tr:nth-child(even) {
background-color: #0000ff;
color: #ffffff;
}
6:33 pm on Apr 11, 2017 (gmt 0)

Full Member from GB 

10+ Year Member

joined:May 20, 2003
posts: 274
votes: 0


I appreciate your reply but there no table involved here and it wouldn't have helped as they could not be linked to the replies.

On further consideration I can see my idea would not work as message counts would increase in various threads which could cause replies in a particular thread to all be even or odd depending on when they were posted.

The only way I can do it is to alter the template and php which is just beyond me.
6:41 pm on Apr 11, 2017 (gmt 0)

Senior Member

WebmasterWorld Senior Member Top Contributors Of The Month

joined:Apr 1, 2016
posts: 2662
votes: 794


It does not need to be a table it can be any repeated element. eg: .someclass:nth-child(even){}
more info on the nth-child css selector here:
[w3schools.com...]