Here's a PHP example of mine. Can anyone find a shorter/easier way to do this?
<? foreach($posts as $post){?> <div class="<?=($c++%2==1)?‘odd’:NULL?>"> <?=$post?> </div> <? }?> <style> .odd{background-color:red;} </style>
Examples in other languages would be fun to see as well.
Select the range of cells that you want to format. Click Home > Format as Table. Pick a table style that has alternate row shading. To change the shading from rows to columns, select the table, click Design, and then uncheck the Banded Rows box and check the Banded Columns box.
The AlternateBackColor property contains a numeric expression that corresponds to the color used to display on alternate rows of the specified section. Use the Color Builder to set this property by choosing the Build button to the right of the property box in the property sheet.
Fundamentally - no. That's about as easy as it gets. You might rewrite it a bit shorter/cleaner, but the idea will be the same. This is how I would write it:
$c = true; // Let's not forget to initialize our variables, shall we? foreach($posts as $post) echo '<div'.(($c = !$c)?' class="odd"':'').">$post</div>";
If you'd like to have less in-line PHP, a great way of doing it is via JavaScript.
Using jQuery, it's simply:
<script type="text/javascript"> $('div:odd').css('background-color', 'red'); </script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With