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. Link to comment https://forums.phpfreaks.com/topic/257010-div-backgrounds-different-every-other-one/ 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. Link to comment https://forums.phpfreaks.com/topic/257010-div-backgrounds-different-every-other-one/#findComment-1317516 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? Link to comment https://forums.phpfreaks.com/topic/257010-div-backgrounds-different-every-other-one/#findComment-1317522 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. Link to comment https://forums.phpfreaks.com/topic/257010-div-backgrounds-different-every-other-one/#findComment-1317526 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. Link to comment https://forums.phpfreaks.com/topic/257010-div-backgrounds-different-every-other-one/#findComment-1317529 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 Link to comment https://forums.phpfreaks.com/topic/257010-div-backgrounds-different-every-other-one/#findComment-1317552 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.