Andy11548 Posted February 13, 2012 Share Posted February 13, 2012 Hello. I've seen on alot of websites that thier div tags are 2 different colours. How do I do this? Example: Yellow Orange Yellow etc. Quote Link to comment Share on other sites More sharing options...
requinix Posted February 13, 2012 Share Posted February 13, 2012 Are you talking about alternating coloring? [edit] There's a pure CSS way but it isn't supported everywhere yet. Otherwise whatever code generates the list also decides the coloring for each item in it. Quote Link to comment Share on other sites More sharing options...
Andy11548 Posted February 13, 2012 Author Share Posted February 13, 2012 Yeah, alternating colours. Would that be Javascript or something then if its not purely CSS? Quote Link to comment Share on other sites More sharing options...
requinix Posted February 13, 2012 Share Posted February 13, 2012 It'd be whatever generates the content. Like PHP. First item it prints has one color. Next one has the other. Next one has the first. And so on. Quote Link to comment Share on other sites More sharing options...
Andy11548 Posted February 13, 2012 Author Share Posted February 13, 2012 Could you give me a example of how to do it please? I'll work the rest out from that. Thanks, Andy. Quote Link to comment Share on other sites More sharing options...
spiderwell Posted February 13, 2012 Share Posted February 13, 2012 in PHP i would do it like this: $variable = "blue" while (looping) { $variable = ($variable == "blue") ? "red" : "blue"; echo "<div class=\"$variable\">"; } this uses a ternary(spelling) operator that says if colour is blue return red otherwise return blue. Should be able to work out the rest, the code clearly wont work as is Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.